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

情到浓时终转凉″ 提交于 2019-12-13 15:08:49

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/50455518/is-the-firebase-storage-getdownloadurl-re-usable-or-should-it-always-be-regen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!