如何在将文件上传到Firebase存储时启用“公开共享”?(How to enable “Share publicly” when uploading a file to Firebase stora

编程入门 行业动态 更新时间:2024-10-28 08:31:18
如何在将文件上传到Firebase存储时启用“公开共享”?(How to enable “Share publicly” when uploading a file to Firebase storage?)

Firebase存储使用Google Cloud Platform进行存储。 GCP允许文件“公开共享”选项,以便能够在浏览器中查看此类文件。

以下是有关此主题的GCP文档 。

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

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

编辑:我已经启用了整个桶的公共阅读,虽然它并不理想。

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

Firebase Storage uses Google Cloud Platform for storage. GCP allows the option "Share publicly" on files to be able to view such files in a browser.

Here is the GCP documentation on this topic.

Here you can see the option available via the GUI on the GCP console.

Is it possible to enable the public option when uploading a file via Firebase?

Edit: I've enabled public reading on the whole bucket although it's not ideal.

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>

第二个选项允许您与受信任的个人共享此公开但不可取的URL,并允许他们无需身份验证即可访问内容到Firebase或使用您的应用 - 考虑与Google相册共享家庭照片。 可能这种行为会很好,除非你希望公共共享干净的URL。

正如您所提到的,第三个选项涉及直接访问Google云端存储控制台,并使用干净的URL公开提供文件,这是通过Firebase存储客户端无法提供的。 这将添加第三个URL:

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

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

With Firebase Storage, you're given two URLs that you can use to represent files:

// "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>

The second option allows you to share this public but unguessable URL with trusted individuals, and allows them to access content without authentication to Firebase or using your app--think sharing family photos with Google Photos. Likely this behavior will be good enough, unless you desire public sharing with clean URLs.

The third option, as you mention, involves going directly to the Google Cloud Storage console and making files publicly available with a clean URL, which isn't available via the Firebase Storage client. This would add a third URL:

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

Generally speaking, unless you want people to know and guess your content (hosting static content, website files, etc.), I would not share publicly via GCS, and almost definitely wouldn't go so far as to set the default ACL to always be public (what happens if you add a new feature and no longer want this behavior, you may forget to turn this back off again...).

更多推荐

GCP,Firebase,option,文件,选项,电脑培训,计算机培训,IT培训"/> <meta name="des

本文发布于:2023-08-03 03:39:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1383194.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件上传   如何在   enable   Firebase   Share

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!