可以';t使用Google PHP客户端将“内容类型”设置为“Google存储”


Can't set Content-type to Google Storage with the Google PHP Client

我使用的是谷歌api php客户端

这是我上传.jpg图片的地方。

$postbody = array("data" => $imgData);
$gso = new Google_StorageObject();
$gso->setName($imageName);
$contentType = 'image/jpg';
$gso->setContentType($contentType);
$resp = $objects->insert('bucket-name', $gso, $postbody);

通过检查$gso,正在添加ContentType,但在云控制台中添加了默认的application/octet-stream类型。

是否有其他设置内容类型的方法?

试试这个,它对我有效:

$postbody = array('mimeType' => 'image/jpeg', "data" => $imgData);
$gso = new Google_StorageObject();
$gso->setName($imageName);
$resp = $objects->insert('bucket-name', $gso, $postbody);

"mimeType"似乎是一个参数。看看中的第39行https://code.google.com/p/google-api-php-client/source/browse/tags/0.6.7/src/service/Google_ServiceResource.php

这听起来像个bug。我建议将其提交给googleapiphp客户端。

与此同时,还有一个变通办法。谷歌云存储将内容类型视为任何其他元数据。上传对象后,可以使用$objects->update()方法更改对象的内容类型。