将 gcloud 用于 node.js 如何公开共享 google 云存储桶图像

Using gcloud for node.js how to share google cloud bucket images publicly

为了将图像存储在我的 Google 云存储桶中,我使用了 @google-cloud/storage npm 模块。现在我的图片上传成功了。我想公开分享它,但在文档中没有提到参数。相反,我必须手动公开分享我的所有图像。有没有办法以编程方式与 google-cloud/storage 公开共享图像?

我使用了以下命令,它使我的存储桶默认公开共享。

gsutil defacl set public-read gs://bucketname

要将现有对象标记为公开可读,请使用此示例 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)。