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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With