使用 getDownloadURL 的 Firebase 存储是在每次需要时使用 url 检索文件还是一次将其下载到客户端更好?
Firebase storage with getDownloadURL is it better to retrieve a file with the url everytime needed or to download it to the client once?
在一个应用中,一个头像可以显示在很多地方。
如果我使用
getDownloadURL(avatarRef).then(url => {
imgList.map(img => img.src = url);
})
我的应用程序每次下载 img url 时都会收费吗?
如果是这样,我认为更好的方法是使用 xhr 下载一次图像并将其存储在应用程序中,如下所示
getDownloadURL(avatarRef).then(url => {
const xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
let blob;
xhr.onload = (event) => {
blob = xhr.response;
};
xhr.open('GET', url);
xhr.send();
// when the blob is returned
imgList.map(img => img.src = URL.creatObjectURL(blob);
})
每次从云存储中读取图像数据时,您都需要付费。所以确实最好缓存多次显示的图片
但根据您的代码运行位置,这可能已经发生了。例如,浏览器非常积极地缓存图像。
如果您的环境还没有缓存图像,您可以使用下载 URL 作为文件名的 key/basis 自己存储它们。
在一个应用中,一个头像可以显示在很多地方。 如果我使用
getDownloadURL(avatarRef).then(url => {
imgList.map(img => img.src = url);
})
我的应用程序每次下载 img url 时都会收费吗? 如果是这样,我认为更好的方法是使用 xhr 下载一次图像并将其存储在应用程序中,如下所示
getDownloadURL(avatarRef).then(url => {
const xhr = new XMLHttpRequest();
xhr.responseType = 'blob';
let blob;
xhr.onload = (event) => {
blob = xhr.response;
};
xhr.open('GET', url);
xhr.send();
// when the blob is returned
imgList.map(img => img.src = URL.creatObjectURL(blob);
})
每次从云存储中读取图像数据时,您都需要付费。所以确实最好缓存多次显示的图片
但根据您的代码运行位置,这可能已经发生了。例如,浏览器非常积极地缓存图像。
如果您的环境还没有缓存图像,您可以使用下载 URL 作为文件名的 key/basis 自己存储它们。