I'm using Gcloud PHP library for uploading files to storage buckets and it works fine. But I want to track progress from this upload process, trying to use the uploadProgressCallback
option provided and documented here: https://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.33.0/storage/bucket?method=getResumableUploader
But it's not working, the callable isn't fired at all. I'm new to using callable functions, but I think it's pretty simple. Here's my code below.
function uploadObject($bucketName, $objectName, $source)
{
$storage = new StorageClient();
$bytes = 0;
$bucket = $storage->bucket($bucketName);
$uploader = $bucket->getResumableUploader (
$file = fopen($source, 'r'),
[
'name' => $objectName,
'resumable' => true,
'chunkSize' => 524288,
'uploadProgressCallback' => array($this, 'uploadProgress')
]
);
try {
$object = $uploader->upload();
} catch ( GoogleException $ex ) {
$resumeUri = $uploader->getResumeUri();
$object = $uploader->resume($resumeUri);
}
}
function uploadProgress($bytes) {
$_SESSION['uploadProgress'] = $bytes;
}
Any help would be greatly appreciated...