问题
I have a function in php to upload several files through a stand alone script, the first ones upload fine but the last one that's 16GB around 20 minutes it gets interrumpted for no reason and the upload stops. The auth is already handled, so I don't know what may be causing this issue. Here's the code and the error that it outputs:
function insertFile($client,$service,$filePath,$name,$fId){
$file = new Google_Service_Drive_DriveFile();
$file->title = $name;
$parent = new Google_Service_Drive_ParentReference();
$parent->setId($fId);
$file->setParents(array($parent));
$chunkSizeBytes = 1 * 1024 * 1024;
$client->setDefer(true);
$request = $service->files->insert(
$file,
array(
'uploadType'=> 'resumable'
)
);
$finfo= finfo_open(FILEINFO_MIME_TYPE);
$media = new Google_Http_MediaFileUpload(
$client,
$request,
finfo_file($finfo, $filePath),
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize($filePath));
$status = false;
$handle = fopen($filePath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
$result = false;
if($status != false) {
$result = $status;
}
fclose($handle);
$client->setDefer(false);
}
Error:
PHP Fatal error: Uncaught exception 'Google_IO_Exception' with message 'HTTP Error: Unape=resumable&upload_id=AEnB2UoRrzX46hJ02lIDkCJi03MFbE2KVP2LDCBOgnuiclONk3sBvSctZxW3NxsWt /libs/google-api-php-client/src/Google/IO/Stream.php
Stack trace:
#0 /libs/google-api-php-client/src/Google/IO/Abstract
#1 /libs/google-api-php-client/src/Google/Http/MediaF
#2 /root/name.php(199): Google_Http_MediaFileUpload->nextChunk(
#3 /root/name.php(102): insertFile(Object(Google_Client), /libs/google-api-php-client/src/Google/IO/Stream.php on l
回答1:
According to: https://gae-php-tips.appspot.com/2013/12/23/getting-started-with-the-cloud-datastore-on-php-app-engine/
The problem is in the Stream library, inside the IO folder. "As a temporary workaround, try commenting out the following clause from IO/Stream.php at line 107:"
if (!$this->client->getClassConfig("Google_Http_Request", "disable_gzip")) {
$url = self::ZLIB . $url;
}
EDIT: Still didn't work, trying with the MediaFileUpload hotfix of doing the following code in lines 240~ish:
private function transformToUploadUrl()
{
$base = 'https://www.googleapis.com'; //Hardcoded, cambiar si
$this->request->setBaseComponent($base . '/upload');
}
来源:https://stackoverflow.com/questions/30676478/resumable-upload-gets-interrumpted-after-few-gb