Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Firebase Storage getDownloadURL() re-usable, or should it always be regenerated?

Is this a good practice to save in the database and reuse the url returned by angularfire2's getDownloadURL() rather than executing getDownloadURL() every time I need to display an image from Firebase Storage?

If I use getDownloadURL() in my component, images are reloaded every time I access the component. I would like to avoid that. If I save the url in my database after the image was uploaded and then use this url every time I need to display the image this solves the problem. However, maybe it's not the right way to do it, and Firebase storage might update the urls at some point.

like image 955
artask Avatar asked Oct 17 '22 18:10

artask


1 Answers

yes, you should store that downloadURL that is generated from the StorageReference of the file inside your database structure in that way you are avoiding creating a new file or the same one to get another downloadURL , in this case , you can also access this image url from anywhere in your code with DatabaseReference and show it anywhere you want.

PS: regenerating the download url implies to reupload the same image and regenerate a new downloadURL, in this case you are wasting networking resources since you are re-doing calls to firebase storage to store the same file, by the way , the file will be replaced but you will be wasting resources. Just upload it once, get the downloadURL, store it in your Database and then retrieve it wherever you would like.

like image 124
Gastón Saillén Avatar answered Oct 20 '22 22:10

Gastón Saillén