将文件上传到 Firebase 存储时如何启用 "Share publicly"?

How to enable "Share publicly" when uploading a file to Firebase storage?

Firebase 存储使用 Google 云平台进行存储。 GCP 允许文件上的选项 "Share publicly" 能够在浏览器中查看此类文件。

这里是 GCP documentation on this topic.

在这里您可以看到通过 GCP 控制台上的 GUI 可用的选项。

是否可以在通过 Firebase 上传文件时启用 public 选项?

编辑:我已经启用 public 读取整个存储桶,尽管它并不理想。

gsutil defacl ch -u allUsers:R gs://<bucket>

使用 Firebase 存储,您有两个 URL 可以用来表示文件:

// "Private" internal URL, only accessible through Firebase Storage API
// This is protected by Firebase Storage Security Rules & Firebase Auth
gs://bucket/object

// "Public" unguessable URL, accessible by anyone with the link
// This is secured because that token is *very* hard for someone to guess
https://firebasestorage.googleapis.com/v0/bucket/object?alt=media&token=<token>

第二个选项允许您与受信任的人分享此 public 但不可猜测 URL,并允许他们访问内容而无需 Firebase 身份验证或使用您的应用程序——想想与Google 照片。可能这种行为就足够了,除非你希望 public 与干净的 URL 分享。

正如您提到的,第三个选项涉及直接进入 Google 云存储控制台并使文件 public 仅可用 URL,而后者不可用通过 Firebase 存储客户端。这将添加第三个 URL:

// "Public" clean URL, accessible and guessable
// Not secure, typically used for public, static content
https://storage.googleapis.com/v0/bucket/object

一般来说,除非你想让人们知道和猜测你的内容(托管静态内容、网站文件等),否则我不会分享publicly通过 GCS,并且几乎肯定不会将默认 ACL 设置为始终 public(如果您添加新功能并且不再需要此行为会发生什么,您可能会忘记将其关闭再次......)。