【问题标题】:Make files publicly readable, but not whole bucket使文件公开可读,但不是整个存储桶
【发布时间】:2017-05-09 02:50:42
【问题描述】:

我正在将文件从我的服务器上传到我的存储桶foobar。上传文件的路径为foobar/uploads/avatars/123456789.jpg

我希望用户能够通过像 https://storage.googleapis.com/foobar/uploads/avatars/123456789.jpg 这样的公共 https 链接访问此文件。该链接必须无需登录任何 Google 帐户即可访问。 我希望用户能够通过https://storage.googleapis.com/foobar/https://storage.googleapis.com/foobar/uploads/avatars/ 之类的链接或其他方式浏览整个存储桶。

我正在使用@google-cloud/storage 上传文件。如何使用 ACL 实现这些设置?

【问题讨论】:

    标签: google-cloud-storage google-cloud-sdk


    【解决方案1】:

    对于现有对象:

    file.makePublic(function(err, apiResponse) {});
    

    上传新对象时,使用选项public,相当于指定options.predefinedAcl = 'publicRead'。根据您的上传方式,您可能会更改您的 createWriteStream 调用,如下所示:

    file.createWriteStream({public: true, metadata: {...}})
    

    【讨论】:

      猜你喜欢
      • 2019-04-03
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 1970-01-01
      相关资源
      最近更新 更多