this.downloadTask
.config({
fileCache : true,
path : RNFetchBlob.fs.dirs.DocumentDir + `/yourApp/${fileUniqueId}.mp3`
})
.fetch('GET', downloadURL, {});
this.downloadTask
.progress({ interval : 100 }, (received, total) => {
console.log('progress ' + Math.floor(received/total*100) + '%');
progressCb(Math.floor(received/total*100))
})
.then(async (res)=>{
console.log("then response",res);
console.log('The file saved to ', res.path());
const filePath = 'file://' + res.path();
//save file path in AsyncStorage
let saveList = {};
const downloadList = await AsyncStorage.getItem("@download");
if(downloadList)
saveList = JSON.parse(downloadList);
saveList[contentKey] = filePath;
return AsyncStorage.setItem("@download",JSON.stringify(saveList))
})
.then(()=>{
finishCb();
})
.catch((err)=>{
//you must add this line. If you don't add, your app users waste they're storage
RNFetchBlob.fs.unlink(RNFetchBlob.fs.dirs.DocumentDir + `/yourApp/${fileUniqueId}.mp3`);
console.log(err)
})