【发布时间】:2017-12-27 03:41:33
【问题描述】:
使用react-native-fs从url下载文件,当下载进度达到100%时,我会调用另一个函数。但是,RNFS.downloadFile 无法正确跟踪进度。
_downloadFile = () =>{
const downloadDest = `${RNFS.ExternalDirectoryPath}/Monstro/${((Math.random() * 1000) | 0)}.jpg`;
let DownloadFileOptions = {
fromUrl: "https://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Boothferry_Road%2C_Goole.jpg/220px-Boothferry_Road%2C_Goole.jpg",
toFile: downloadDest,
begin: this._downloadFileBegin,
progress: this._downloadFileProgress,
background:false,
progressDivider:1
};
RNFS.downloadFile(DownloadFileOptions);
}
_downloadFileBegin = () =>{
console.log("Download Begin");
}
_downloadFileProgress = (data) =>{
const percentage = ((100 * data.bytesWritten) / data.contentLength) | 0;
const text = `Progress ${percentage}%`;
console.log(text);
if(percentage == 100) //call another function here
}
不是每次console.log 在_downloadFileProgress 中都显示Progress 100%,所以我很难检查进度。我是否错过了某些设置,或者有任何其他方法可以跟踪进度
【问题讨论】:
标签: reactjs react-native react-native-fs