我无法使用此api执行可恢复上传请帮助我。此代码正常工作直到我使用可恢复上传。我可以使用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/"
}
}**
答案 0 :(得分:0)
您的上传网址不正确,因为无论何时您必须上传文件,在云存储桶中上传网址的路径都非常重要。不仅适用于Google Cloud,甚至适用于Amazon S3或任何其他云存储环境。这些存储桶为您的文件上传位置创建标准路径,并通过CDN边缘提供。因此有必要设置上传路径。
要制作标准的基于HTML的文件上传,请参阅此链接。 https://cloud.google.com/appengine/docs/standard/php/googlestorage/user_upload
https://cloud.google.com/appengine/docs/standard/php/googlestorage/