Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is Firebase storage URL static?

I have a list of contacts and each of those has a profile photo which is stored in Firebase storage. An official way of getting the images would be to fetch the URL using the Firebase storage SDK and set it as src in img element.

            firebaseApp.storage().ref("profilePhotos/" + officeId + ".jpg").getDownloadURL().then(function (url) {
                this.photoUrl = url;
            }.bind(this)).catch(function (error) {
                console.log("Photo error"); // TODO: handler
            });

This is quite cumbersome when I have to load multiple files (as in contact list). Is the file URL received above static? Can I store it in the database in the profile information and use it directly?

Thanks

like image 494
Jan Beneš Avatar asked Apr 04 '17 07:04

Jan Beneš


People also ask

How can I get public URL of Firebase storage?

send(publicUrl); }); Alternatively, if you need a publicly accessible download URL, see this answer which suggests using getSignedUrl() from the Cloud Storage NPM module because the Admin SDK doesn't support this directly: You'll need to generate a signed URL using getSignedURL via the @google-cloud/storage NPM module.

What is the difference between Firebase database and storage?

Firebase Hosting hosts the HTML, CSS, and JavaScript for your website as well as other developer-provided assets like graphics, fonts, and icons. Firebase Storage stores files such as images, videos, and audio as well as other user-generated content.

Is Firebase storage realtime?

Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud. The Firebase Realtime Database stores JSON application data, like game state or chat messages, and synchronizes changes instantly across all connected devices.


2 Answers

In my experience, the download urls are static. Also if you look at the entry in the database below the download url you can see an option to recreate the download url.

Storing the download url in the Realtime Database is a great way to keep track of those download urls. I would use the push method to hold it in a folder in the database.

The way they use .push in the Realtime Database docs example will create a pattern of storage and retrieval that should solve your problem.

.push for making and entry, chained with .key for retrieval later:

var newPostKey = firebase.database().ref().child('posts').push().key;

.once for reading the data at the reference you want with a .then

firebase.database().ref('/users/' + userId).once('value').then(...)
like image 23
illuminatedSpace Avatar answered Sep 21 '22 13:09

illuminatedSpace


A very common pattern is to store the download URL of a file in Realtime Database for easy use later on. Download URLs should work until you choose to revoke them.

like image 197
Doug Stevenson Avatar answered Sep 17 '22 13:09

Doug Stevenson