如何启用“公开共享"将文件上传到Firebase存储时? [英] How to enable "Share publicly" when uploading a file to Firebase storage?

查看:85
本文介绍了如何启用“公开共享"将文件上传到Firebase存储时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

这是有关此主题的 GCP文档.

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

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

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

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

尽管不理想,但我已经在整个存储桶上启用了公共阅读功能.

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

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

推荐答案

使用Firebase Storage,您将获得两个可用于表示文件的URL:

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>

第二个选项可让您与受信任的个人共享此公开但无法猜测的URL,并允许他们访问内容而无需通过Firebase进行身份验证或使用您的应用程序-认为与Google相册共享家庭照片.除非您希望使用干净的URL进行公开共享,否则这种行为可能会足够好.

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.

您提到的第三个选项涉及直接进入Google Cloud Storage控制台,并使用清晰的URL公开提供文件,而该URL无法通过Firebase Storage客户端获得.这将添加第三个URL:

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

通常来说,除非您希望人们知道和猜测您的内容(托管静态内容,网站文件等),否则我不会通过GCS公开分享,并且几乎绝对不会只要将默认ACL设置为始终是公共的(如果您添加了新功能并且不再想要此行为,您可能会忘记再次将其关闭...会发生这种情况.)

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...).

这篇关于如何启用“公开共享"将文件上传到Firebase存储时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆