Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

enter image description here

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>
like image 241
Pier Avatar asked Jun 08 '16 23:06

Pier


People also ask

How do I give storage permissions in Firebase?

go to "Storage" Select "Rules" tab and edit rules as per below: service firebase. storage { match /b/{bucket}/o { match /{allPaths=**} { // Allow access by all users allow read, write: if request. auth !=

How can upload image in Firebase storage and get URL?

Image URL is obtained by uploading an image to firebase bucket and then that can return back a URL that URL is a permanent URL which can be open anywhere. Then a user can use this URL for any purpose in its application.

Is Firebase storage same as Google Cloud Storage?

Cloud Storage for Firebase stores your files in a Google Cloud Storage bucket, making them accessible through both Firebase and Google Cloud. This allows you the flexibility to upload and download files from mobile clients via the Firebase SDKs for Cloud Storage.

How do I upload documents to Firebase?

Upload from a Blob or File Once you've created an appropriate reference, you then call the uploadBytes() method. uploadBytes() takes files via the JavaScript File and Blob APIs and uploads them to Cloud Storage. Learn more about the tree-shakeable Web v9 modular SDK and upgrade from version 8.


1 Answers

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

like image 116
Mike McDonald Avatar answered Sep 29 '22 13:09

Mike McDonald