如何从浏览器访问Google Cloud Storage存储桶中的文件? [英] How can I access files from a Google Cloud Storage bucket from a browser?

查看:204
本文介绍了如何从浏览器访问Google Cloud Storage存储桶中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Cloud Storage存储我的Google App Engine应用程序的图像,并且试图像这样访问图像:

<img src="https://storage.googleapis.com/BUCKET_NAME/IMAGE_NAME">

但是,这将显示访问被拒绝"或向我显示Google登录提示. 然后,我尝试使用签名URL 授予客户端访问权限. /p>

我生成了要签名的URL,如下所示:

String HTTP_Verb = "GET";
String Expiration = "1361993085";
String Canonicalized_Resource = "/bucket_name/sub_directory";
String stringToSign = HTTP_Verb + "\n" + Expiration + "\n" + Canonicalized_Resource;

然后使用p12文件生成Base64并使用Java进行编译,但出现此错误:

The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.

我在这里做错了什么?是否可以通过身份验证从GCS访问图像?

解决方案

最后两天后,它开始工作了.答案是: 我的处理方法是错误,不需要签名的URL.我只需要将我的存储桶添加为公开读取即可,以便我可以从浏览器请求中读取它.就这样. 打开gsutil,输入以下内容:

gsutil -m acl -r set public-read gs://BUCKET_NAME

,并将其设置为以后所有上传的默认设置

gsutil -m defacl set public-read gs://BUCKET_NAME

希望它对某人有帮助!

感谢@kctang!

I am using Google Cloud Storage to store images for my Google App Engine application and I'm trying to access the images like so:

<img src="https://storage.googleapis.com/BUCKET_NAME/IMAGE_NAME">

However, this displays "Access Denied" or presents me with a Google login prompt. Then I tried using Signed URLs to grant the client access.

I generated the URL to be signed like so:

String HTTP_Verb = "GET";
String Expiration = "1361993085";
String Canonicalized_Resource = "/bucket_name/sub_directory";
String stringToSign = HTTP_Verb + "\n" + Expiration + "\n" + Canonicalized_Resource;

And then generated Base64 with the p12 file and compiled using Java, but I got this error:

The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.

What am I doing wrong here? Is there way I can access images from GCS without authentication?

解决方案

And finally after 2 days, got it working.here is the answer: My approach for this is wrong, no need for signed URL. i need to just add my bucket as public-read so that i can read it from browser request. thats all. open gsutil, type this:

gsutil -m acl -r set public-read gs://BUCKET_NAME

and set this as default for all future uploads

gsutil -m defacl set public-read gs://BUCKET_NAME

hope it helps someone !

Thanks to @kctang !

这篇关于如何从浏览器访问Google Cloud Storage存储桶中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆