Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tip] How to Immediately delete canceled files during download + Android Task.cancel() not working with catch error #182

Closed
bang9 opened this issue Sep 12, 2018 · 2 comments

Comments

@bang9
Copy link

bang9 commented Sep 12, 2018

Nevertheless you cancel the download task, file is exist exactly in your app caches

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)
    })

Android side download task cancel is not working

You can find solution in this PR(past repo), It works well for me
wkh237#568

@BaderSerhan
Copy link

Is the past repository's solution implemented here?

@bang9
Copy link
Author

bang9 commented Dec 20, 2018

Is the past repository's solution implemented here?

@BaderSerhan maybe not

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants