[英]File Upload error using Google Client API to Google Cloud Storage
自2015年以来,我一直在使用Google Cloud Storage API,现在我刚刚将PHP客户端库更新为最新版本,并且在将文件上传到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."
}
我也需要使用Google客户端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();
}
我只是通过将mimeType放入请求参数来解决它
$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(
'mimeType' => $image_type,
'data' => file_get_contents($data["image_temp_name"]),
'uploadType' => 'multipart',
'predefinedAcl'=>'publicRead'
// 'contentEncoding'=>'gzip'
));
}
catch(Exception $e)
{
echo $e->getMessage();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.