【问题标题】:Using gcloud for node.js how to share google cloud bucket images publicly使用 gcloud for node.js 如何公开共享谷歌云存储桶图像
【发布时间】:2016-09-07 17:52:02
【问题描述】:
要将图像存储在我的 Google Cloud Storage 存储桶中,我使用了 @google-cloud/storage npm 模块。现在我的图片上传成功了。我想公开分享它,但在文档中没有提到参数。相反,我必须手动公开分享我的所有图像。有没有办法通过 google-cloud/storage 以编程方式公开共享图像?
【问题讨论】:
标签:
node.js
image
google-cloud-storage
gcloud
【解决方案1】:
要将现有对象标记为公开可读,请使用此示例from the docs:
file.acl.add({
entity: 'allUsers',
role: gcs.acl.READER_ROLE
}, function(err, aclObject) {});
进行上传时,可以像上面那样设置 ACL,使用预定义的 ACL“publicRead”,或者在调用上传时只指定选项“public”(参见docs for the upload method)。
【解决方案2】:
我使用了下面的命令,它使我的存储桶默认公开共享。
gsutil defacl set public-read gs://bucketname