问题
I'm using google-api-php-client
Here's the bit where I upload a .jpg image.
$postbody = array("data" => $imgData);
$gso = new Google_StorageObject();
$gso->setName($imageName);
$contentType = 'image/jpg';
$gso->setContentType($contentType);
$resp = $objects->insert('bucket-name', $gso, $postbody);
By inspecting $gso
ContentType is being added but in the cloud console is added with the default application/octet-stream
type.
Is there another way to set the content type?
回答1:
Try this, it worked for me:
$postbody = array('mimeType' => 'image/jpeg', "data" => $imgData);
$gso = new Google_StorageObject();
$gso->setName($imageName);
$resp = $objects->insert('bucket-name', $gso, $postbody);
It seems 'mimeType' its a parameter. Take a look at line 39 in https://code.google.com/p/google-api-php-client/source/browse/tags/0.6.7/src/service/Google_ServiceResource.php
回答2:
That sounds like a bug. I'd suggest filing it with google-api-php-client.
In the meanwhile, there is a workaround. Google Cloud Storage treats the Content Type like any other metadata. You can change the content type of an object after you upload it by by using the $objects->update()
method.
来源:https://stackoverflow.com/questions/20060445/cant-set-content-type-to-google-storage-with-the-google-php-client