Using react-native-fs for download file from url, when download progess percent reached 100%, I will call another function. However, RNFS.downloadFile
not keep track the progress correctly.
_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
}
Not every time console.log
in _downloadFileProgress
show Progress 100%
, so it is harder for me to check the progress. Did I miss out some setting, or there is any other ways to keep track the progress