I use the following code to upload mp4 files from the server to Google Drive:
// vars
$path = FCPATH . '/assets/files/test/';
$filename = $video['recording_id']. '.' . strtolower($video['file_type']);
$mimeType = get_mime_by_extension($filename);
$destination = $path . $filename;
// chunk size
$chunkSizeBytes = 1 * 1024 * 1024;
// service
$file2 = new Google_Service_Drive_DriveFile();
$file2->setParents(array($folder_topic));
$file2->setName($filename);
$file2->setMimeType($mimeType);
//media
$client->setDefer(true);
$request = $service->files->create($file2, [ 'uploadType' => 'resumable', 'fields' => 'id' ]);
$media = new Google_Http_MediaFileUpload(
$client,
$request,
$mimeType,
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize($destination));
$media->setChunkSize($chunkSizeBytes);
// upload
$status = false;
$handle = fopen($destination, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$uploadStatus = $media->nextChunk($chunk);
}
fclose($handle);
$client->setDefer(false);
echo '------ Upload OK ('.date('H:i:s').') :: '.$filename."<br>".PHP_EOL;
flush();
ob_flush();
The code works fine with files under 2GB, over this, I get the following error:
An uncaught Exception was encountered
Type: Google_Service_Exception
Message: Failed to parse Content-Range header.
Filename: D:xampphtdocsoomapplicationhird_partygooglesrcGoogleHttpREST.php
Line Number: 118
I've tried to change the chunk size to 100 * 1024 * 1024 but I have the same result. Do I need to change something in the code, server or in the API console?
I use: PHP 5.6, Codeigniter 3, Google OAuth API (unlimited quota)
question from:https://stackoverflow.com/questions/66065308/php-drive-api-failed-to-parse-content-range-header-upload-big-files