【发布时间】:2020-04-29 08:47:40
【问题描述】:
我在后端数据库中存储了一些图像/视频的 Firebase 存储路径,移动客户端在需要时使用这些路径来获取下载 URL:
import {firebase} from '@react-native-firebase/storage';
// e.g. 'images/stars.jpg'
const getDownloadUrlForFilePath = (filePath: string | null): Promise<string> => {
if (filePath === null) {
throw 'Path is null!';
}
return getDownloadUrlForRef(firebase.storage().ref(filePath));
};
const getDownloadUrlForRef = (ref): Promise<string> => {
return ref.getDownloadURL();
};
问题是我在很多地方都需要相同的图像。因此,我经常致电getDownloadURL() 来检索相同的下载网址。这导致手机对我调试网络流量时出现的相同资源发出多个 http 请求。
在我当前的实现中,我没有将检索到的下载 URL 存储在移动客户端中的任何位置。
我想找到一种方法,让应用只为同一路径获取一次下载 URL 并缓存它。 Firebase SDK 是否支持此功能?
【问题讨论】:
标签: typescript react-native google-cloud-storage firebase-storage react-native-firebase