Skip to content
This repository has been archived by the owner on Mar 16, 2019. It is now read-only.

Downloading using download manager, Cannot Delete the file #236

Closed
drblmb opened this issue Jan 18, 2017 · 10 comments
Closed

Downloading using download manager, Cannot Delete the file #236

drblmb opened this issue Jan 18, 2017 · 10 comments

Comments

@drblmb
Copy link

drblmb commented Jan 18, 2017

On Android, I downloaded a PDF file using Download Manager...then, when I delete the file later, it reports success, but the files are not being removed from the system. I can see them in Recent Files and Download History.

RNFetchBlob.session('pdf').dispose().then(() => { console.log('Succeeded'); }

I also tried just deleting the file with RNFetchBlob.fs.unlink, and it also reports Succeeded, but the file is still there. How do I really delete the files?

@wkh237
Copy link
Owner

wkh237 commented Jan 25, 2017

@drblmb , files created by download manager should be scanned again using fs.scanFile so that it removed from Android media database.

@drblmb
Copy link
Author

drblmb commented Jan 28, 2017

@wkh237 , can you give me an example of this? The examples of using scanFile show it resolving a promise that returns no values.

.then((res) => RNFetchBlob.fs.scanFile([ { path : res.path(), mime : 'audio/mpeg' } ]))
.then(() => {
// scan file success
})
.catch((err) => {
// scan file error
})

In my case, I was downloading using DownloadManager which returns a path. What does scanFile do?

Thanks!

@drblmb
Copy link
Author

drblmb commented Mar 30, 2017

@wkh237, or anyone please, can someone show me how to delete a file I've downloaded with download manager?

@wkh237
Copy link
Owner

wkh237 commented Mar 31, 2017

@drblmb , from my understanding if you're going to remove a file downloaded by Android Download Manager, you need to do these 2 things :

  1. remove the file using fs.unlink
  2. scan the path again (fs.scanFile)

@wkh237 wkh237 closed this as completed Apr 14, 2017
@drblmb
Copy link
Author

drblmb commented Apr 14, 2017

fs.unlink says it worked, but then after I close my app, I'm able to go to download manager and still open the file. It isn't really deleted, so this issue cannot be closed yet

@rolldone
Copy link

me too, unlink does not working..

@wkh237 wkh237 reopened this Apr 15, 2017
@wkh237
Copy link
Owner

wkh237 commented Apr 15, 2017

Okay, just closed it due to there's no response. Reopen this one.

@wkh237
Copy link
Owner

wkh237 commented Apr 15, 2017

@drblmb , @rolldone , as the default location the Download Manager uses might be somewhere you're app does not have access right. I think you can set a custom download location for ensuring the app has access right to the file after it's completed. But keep in mind that the path must on external storage (like DCIMDir)

RNFetchBlob.config({
    addAndroidDownloads : {
      useDownloadManager : true,
      title : new Date().toLocaleString() + ' - #236 test.png',
      path : PathToTheFile
    }
  })

I've also added some error handling to Download Manager and fs API which should throw an error when the file is not deleted.

You can checkout the commit from branch issue-236.

Will add related information to the documentation, thanks 👍

@drblmb
Copy link
Author

drblmb commented Apr 15, 2017

@wkh237 It appears this is working well if I use external storage. Thank you!

@drblmb drblmb closed this as completed Apr 15, 2017
@saravanakumargn
Copy link

saravanakumargn commented Jan 1, 2018

This might help to delete pdf file.

        RNFetchBlob.fs.exists(this.path)
          .then((exist) => {
            if (exist) {
              RNFetchBlob.fs.unlink(this.path);
            }
          });

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

No branches or pull requests

4 participants