【问题标题】:How can I access files from a Google Cloud Storage bucket from a browser?如何从浏览器访问 Google Cloud Storage 存储桶中的文件?
【发布时间】:2013-11-21 12:28:36
【问题描述】:

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

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

但是,这会显示“拒绝访问”或向我显示 Google 登录提示。 然后我尝试使用Signed URLs 授予客户端访问权限。

我生成了要签名的 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 访问图像?

【问题讨论】:

    标签: google-cloud-storage


    【解决方案1】:

    终于在 2 天后,让它工作了。这是答案: 我的方法是错误,不需要签名 URL。我只需将我的存储桶添加为 public-read 以便我可以从浏览器请求中读取它。就这样。 打开 gsutil,输入:

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

    并将其设置为所有未来上传的默认值

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

    希望对某人有所帮助!

    感谢@kctang!

    【讨论】:

    • 如果在 PATH 上设置了 gsutll,则不需要 .py:=> gsutil -m defacl set public-read gs://BUCKET_NAME => gsutil -m acl set -R -a public-read gs://BUCKET_NAME
    • 我们还需要为组和用户输入一个授权 ID 或电子邮件,并为bucket permission 的域输入一个域,否则您将收到如下错误消息:'DefAclCommand' object has no attribute 'continue_on_error'
    【解决方案2】:

    gsutil 已更新,您现在需要这样做:

    gsutil -m acl -r set public-read gs://bucket-name
    gsutil -m defacl set public-read gs://bucket-name
    

    附:对于不熟悉gsutilhere is how to install it的人。

    【讨论】:

      【解决方案3】:

      对于更一般的答案,访问 gs:// 网址的方法是使用以下格式:

      https://console.cloud.google.com/storage/browser/[BUCKET_NAME]/

      例如,如果您尝试访问的存储桶是 Landsat 公共数据集gs://gcp-public-data-landsat/,那么您将使用以下网址访问该存储桶:https://console.cloud.google.com/storage/gcp-public-data-landsat/

      这是与访问存储桶相关的文档:

      1. https://cloud.google.com/storage/docs/access-public-data
      2. https://cloud.google.com/storage/docs/cloud-console

      希望这会有所帮助!

      【讨论】:

        【解决方案4】:

        string to be signed 中缺少 content-md5 和 content-type 字段。它们可以是空白的,但您仍然需要 \n 分隔符。请参阅 this question 了解构造要签名的字符串的工作示例。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2020-11-23
          • 2020-05-05
          • 2018-06-18
          • 2019-02-04
          • 2017-11-29
          • 2019-12-24
          • 2023-02-21
          相关资源
          最近更新 更多