Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase storage - getting image URL [duplicate]

I have started to use firebase (Firebase for web) for my backend. I can handle Firebase Realtime Database quite well, but I do not clearly understand how Firebase Storage (for images, videos etc.) works.

Basically I would like to have some list of news on my website each item with some small picture. So I uploaded these pictures to Firebase Storage, but how can I access their URL (need it for my <img/> src attribute)?

like image 386
exoslav Avatar asked Jul 17 '16 17:07

exoslav


People also ask

How do I remove image URL from Firebase storage?

To delete a file, first create a reference to that file. Then call the delete() method on that reference, which returns a Promise that resolves, or an error if the Promise rejects.

How can I get download URL from Firebase storage?

Once you have a reference, you can download files from Cloud Storage by calling the getBytes() or getStream() . If you prefer to download the file with another library, you can get a download URL with getDownloadUrl() .

Do Firebase storage urls expire?

The Firebase Storage token does not expire (see Stack Overflow). Therefore, without any other modifications, our downloadUrl also never expires and remains available. But, is it possible in the Firebase Console to invalidate a specific URL.


1 Answers

Firebase Storage works in a similar way when extracting data. Though there are different ways to retrieve. One of the most important factor is how you save your data. According to which you will be able to retrieve them.

Here:

storageRef.child("users/me/profile.png").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {     @Override     public void onSuccess(Uri uri) {         // Got the download URL for 'users/me/profile.png'     } }).addOnFailureListener(new OnFailureListener() {     @Override     public void onFailure(@NonNull Exception exception) {         // Handle any errors     } });  // Alternatively way to get download URL storageRef.child("users/me/profile.png").getDownloadUrl().getResult();  

The location of child is very crucial and that should be a part of your login.

For example in a news structure, it can be:

storageRef.child("newsID/articleimage/image.jpg") 

newsID - Unique id for each article. IMPORTANT! when you create your article in order to get separate images. and that, "image.jpg" can be downloaded various ways as explained here: Documentation.

like image 62
Tanishq Sharma Avatar answered Oct 25 '22 05:10

Tanishq Sharma