简体   繁体   English

Google Cloud Storage使浏览器下载图像

[英]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. 将文件上传到公开阅读的GCS存储桶后,当我直接访问文件( http://storage.googleapis.com/ /image.png)时,浏览器(Chrome)下载文件,而不显示文件。

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. 使用GCS PHP文件系统库时 ,您可以使用file options参数设置上载对象的Content-Type 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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