【发布时间】:2017-03-28 04:21:53
【问题描述】:
自 2015 年以来,我一直在使用 Google Cloud Storage API,现在我刚刚将 PHP client library 更新为最新版本,但在将文件上传到 Google Cloud Storage 时出现了一些错误
我的错误
{
"domain":"global",
"reason":"invalid",
"message":"Content-Type specified in the upload (application/octet-stream) does not match Content-Type specified in metadata (image/jpeg). If it was a simple upload (uploadType=media), the Content-Type was specified as a bare header. If it was a multipart upload (uploadType=multipart), then the Content-Type was specified in the second part of the multipart. If it was a resumable upload (uploadType=resumable), then the Content-Type was specified with the X-Upload-Content-Type header with the start of the resumable session. For more information, see https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload."
}
而且我还需要使用谷歌客户端 api 进行可恢复上传的帮助
我上传文件的代码:
$storageObject->setContentType($image_type);
$storageObject->setName($name);
$storageObject->setSize(filesize($data["temp_name"]));
$storageObject->setMetadata($meta_data);
try{
$res = $storageService->objects->insert(
$data["bucket_name"],
$storageObject,
array(
'data' => file_get_contents($data["image_temp_name"]),
'uploadType' => 'multipart',
'predefinedAcl'=>'publicRead'
// 'contentEncoding'=>'gzip'
));
}
catch(Exception $e)
{
echo $e->getMessage();
}
【问题讨论】:
-
您是否更改了 API 的较新版本(如果是从哪个版本更改为哪个版本),还是您只是更新了 PHP 客户端库?
-
是的,我已更改为最新版本的谷歌客户端 php
-
@DaImTo 请帮助我使用谷歌客户端 php API 或任何示例链接恢复上传到谷歌云存储
-
我也在做同样的事情。检查这个stackoverflow.com/questions/43062584/…
标签: php file-upload google-api google-cloud-storage google-api-php-client