【发布时间】:2017-08-21 02:46:26
【问题描述】:
我无法使用此 api 执行可恢复上传,请帮助我。此代码工作正常,直到我使用可恢复上传。我可以使用 Multipart 上传文件,但不能使用 multipart 上传大文件
我的代码
$storageObject->setName("FIle Name.mp3");
$storageObject->setBucket($data["bucket_name"]);
$mimetype = mime_content_type($data["temp_name"]);
$chunkSizeBytes = 1 * 1024 * 1024;
$storageClient->setDefer(true);
$status = false;
$filetoupload = array('name' => "FIle Name.mp3",
'uploadType' => 'resumable');
$request = $storageService->objects->insert(
$data["bucket_name"], $storageObject, $filetoupload );
$media = new Google_Http_MediaFileUpload($storageClient,
$request, $mimetype, null, true, $chunkSizeBytes);
$media->setFileSize(filesize($data["file_temp_name"]));
$handle = fopen($data["file_temp_name"], "rb");
while (!$status && !feof($handle))
{
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
$result = false;
if($status != false) {
$result = $status;
}
$storageClient->setDefer(false);
响应错误
{
"error": {
"errors": [
{
"domain": "global",
"reason": "wrongUrlForUpload",
"message": "Upload requests must include an uploadType URL parameter and a URL path beginning with /upload/",
"extendedHelp": "https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload"
}
],
"code": 400,
"message": "Upload requests must include an uploadType URL parameter and a URL path beginning with /upload/"
}
}**
【问题讨论】:
-
对你的错误做点什么!查看documentation 了解有关恢复中断文件上传的更多信息。
-
错误没有解决办法
-
哦,我明白了,我以为你说你不能恢复上传。错误仍然表明您以错误的方式上传它(documentation)。
-
这是我所知道的多部分的最佳示例。 developers.google.com/drive/v3/web/…
-
multipart 对我来说工作正常,但是当涉及到可恢复时,这个错误就会返回
标签: php google-cloud-storage google-api-php-client resume-upload