简体   繁体   中英

Google Cloud Storage makes browser download image

After uploading a file to a GCS bucket, that is publically readbale, when I access the file directly ( http://storage.googleapis.com/ /image.png) the browser (Chrome) downloads the file, instead of displaying it.

In the Inspector, I can see it is being served with a content type of binary/octet-stream.

How do I make sure the file has the correct content type when retrieving?

When using the GCS PHP Filesystem Library , you can set the Content-Type of the uploaded object using the file options parameter. There is an example of it in the documentation :

$options = ['gs' => ['Content-Type' => 'text/plain']];
$ctx = stream_context_create($options);
file_put_contents('gs://my_bucket/hello.txt', 'Hello', 0, $ctx);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM