【发布时间】:2020-03-06 06:58:55
【问题描述】:
我需要在 react native 中下载 1000 张照片以供离线使用。 我使用适用于 android 的 RNFetchBlob 和适用于 iOS 的 RNFS 来下载所有照片。
安卓版
RNFetchBlob.config({
path: `${Path.path}${fileName}.${type}`,
fileCache: true
}).fetch('GET', result, {})
.progress((received, total) => {
}).then(async res => {
deletePhoto(id)
console.log('downloaded', res)
}).catch((error) => {
downloadFile(fileName, result, type, id)
console.log('error in file download', id)
})
适用于 iOS
RNFS.downloadFile({
fromUrl: result,
toFile:`${Path.path}${fileName}.${type}`,
background: true,
connectionTimeout: 1000 * 10,
readTimeout: 1000 * 10,
discretionary: true,
progressDivider: 1,
progress: (res) => {
// do progress
}
}).promise.then((result) => {
console.log('downloaded', result)
})
.catch(error => {
console.log('error in file download', error)
})
问题
下载 800 个文件所需的时间是 android - 2-3 分钟 取决于网络带宽和 iOS 20 分钟 我不知道我在做什么错了。
任何帮助都会对我有用 提前致谢
【问题讨论】:
标签: ios react-native react-native-fs rn-fetch-blob