I am getting the below error:
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Failed to parse Content-Range header.' in vendor/google/apiclient/src/Google/Http/REST.php:118
Stack trace:
0 vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), NULL)
1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), NULL)
2 vendor/google/apiclient/src/Google/Task/Runner.php(176): call_user_func_array(Array, Array)
3 vendor/google/apiclient/src/Google/Http/REST.php(58):Google_Task_Runner-run()
4 vendor/google/apiclient/src/Google/Client.php(788): Google_Http_R in /var/www/html/website-redesign/application/libraries/hla_app_log/vendor/google/apiclient/src/Google/Http/REST.php on line 118
Code for uploading:
function uploadInBatch($client,$service, $parentId,$backup_file) {
$file = new Google_Service_Drive_DriveFile();
$file->title = 'backup.sql';
$file->setParents(array($parentId));
$filesize = filesize($backup_file);
$chunkSizeBytes = $filesize/20;
// Call the API with the media upload, defer so it doesn't immediately return.
$client->setDefer(true);
$request = $service->files->create($file);
// Create a media file upload to represent our upload process.
$media = new Google_Http_MediaFileUpload(
$client,
$request,
'application/sql',
null,
true,
$chunkSizeBytes
);
$media->setFileSize($filesize);
$status = false;
$handle = fopen($backup_file, "rb");
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
$resumeUri = $media->getResumeUri();
$offset = ftell($handle);
while (!$status) {
if($resumeUri){
$result = $media->resume($resumeUri);
}
fseek($handle, $offset);
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
if(!$status){ //nextChunk() returns 'false' whenever the upload is still in progress
echo 'sucessfully uploaded ' . ($media->getProgress()/$filesize)*100 . ' %';
}
}
fclose($handle);
// Reset to the client to execute requests immediately in the future.
$client->setDefer(false);
}
The above function is used to upload files with around 2GB