Firebase存储getDownloadURL()是否可重用,还是应始终重新生成? [英] Is the Firebase Storage getDownloadURL() re-usable, or should it always be regenerated?

查看:99
本文介绍了Firebase存储getDownloadURL()是否可重用,还是应始终重新生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是保存在数据库中并重用angularfire2的getDownloadURL()返回的url的好习惯,而不是每次需要显示Firebase Storage的图像时都执行getDownloadURL()吗?

如果我在组件中使用getDownloadURL(),则每次访问组件时都会重新加载图像.我想避免这种情况.如果在上载图像后将URL保存在数据库中,然后每次需要显示图像时都使用此URL,则可以解决此问题.但是,也许这不是正确的方法,Firebase存储可能会在某个时候更新网址.

解决方案

是的,您应该将通过文件的StorageReference生成的downloadURL存储在数据库结构中,这样可以避免创建新的文件或同一个文件来获取另一个downloadURL,在这种情况下,您还可以使用DatabaseReference从代码的任何位置访问此图像url,并将其显示在任意位置.

PS:重新生成下载URL意味着重新上传相同的图像并重新生成新的downloadURL,在这种情况下,您正在浪费网络资源,因为您正在重新调用Firebase存储以存储相同的文件,文件将被替换,但您将浪费资源.只需上传一次,获取downloadURL,将其存储在数据库中,然后在任意位置进行检索即可.

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.

这篇关于Firebase存储getDownloadURL()是否可重用,还是应始终重新生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆