使用 Google 客户端 API 到 Google 云存储的文件上传错误
File Upload error using Google Client API to Google Cloud Storage
自 2015 年以来,我一直在使用 Google 云存储 API,现在我刚刚将 PHP client library 更新为最新版本,在将文件上传到 [=27] 时出现一些错误=]云存储
我的错误
{
"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();
}
自 2015 年以来,我一直在使用 Google 云存储 API,现在我刚刚将 PHP client library 更新为最新版本,在将文件上传到 [=27] 时出现一些错误=]云存储
我的错误
{
"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();
}