我在php中有一个函数可以通过一个独立的脚本上传几个文件,第一个上传很好但是最后一个16GB大约20分钟就会无缘无故地上传,上传就停止了。身份验证已经处理完毕,因此我不知道可能导致此问题的原因。这是输出的代码和错误:
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);
}
错误:
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
答案 0 :(得分:0)
问题出在IO文件夹内的Stream库中。 "作为临时解决方法,请尝试在第107行的IO / Stream.php中注释掉以下子句:"
if (!$this->client->getClassConfig("Google_Http_Request", "disable_gzip")) {
$url = self::ZLIB . $url;
}
编辑:仍然没有用,尝试使用MediaFileUpload修补程序在第240行中执行以下代码:ish:
private function transformToUploadUrl()
{
$base = 'https://www.googleapis.com'; //Hardcoded, cambiar si
$this->request->setBaseComponent($base . '/upload');
}