react-native-fs: unlink doesn't delete the picture

Hello,

I use RNFS.unlink() to delete a picture that was taken by react-native-camera.

Here is my code :

RNFS.exists(filepath)
.then((result) => {
  if(result){
    return RNFS.unlink(filepath)
      .then(() => {
        console.log('la photo a été supprimée');
      })
      .catch((err) => {
        console.log("erreur suppression de la photo " + err.message);
      });
  }
})
.catch((err) => {
  console.log(err.message);
});

Where filepath is the name of the picture, for example : file:///storage/emulated/0/Pictures/IMG_20170926_134921.jpg .

After the operation (with no errors), here is the deleted picture :

screenshot_20170926-140213 1

Is there something I didn’t understand ?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 18 (2 by maintainers)

Most upvoted comments

This issue is still persisting!

I am using the library just for removing a video file fetched from react-native-image-picker, after uploading the file to our server, I need to remove that local file from the user device,

It happens as @chad187 has described, It keeps an existing video in Gallery, it is shown as empty video that could not be displayed.

I have to restart the whole mobile device, to get rid of that empty placeholder! Any suggestions, even to till Android to refresh the Gallery list?

I observe the same behavior here.

You should work with state to tell the UIimage that the URL is not existing and should render then somehing else.

@Ignigena, any example for this?

Have you find any work-through to remove this deleted cache image/placeholder?

using RNFS delete file is not working after 1 or 2 days

What about IOS? In iOS its not deleting after unlink success

is this issue solved ? i am getting same issue if you solved this issue please help me

What about IOS? In iOS its not deleting after unlink success

For anyone who may come across this issue in the future who is confused about these gray images left in the device’s gallery:

Android maintains a cache of media files on the device. When a file is deleted, the cache is not necessarily updated. See this Stack Overflow post for more info.

This is why you should call RNFS.scanFile(filePath) when you need to update the cache.

If you’ve still got this issue, use the scanFile API to run the Media Scanner on Android so that it notifies changes to the index, after unlinking the file. #554 has fixed this.

RNFS.unlink(filePath)
  .then(() => {
    console.log('deleted');
    RNFS.scanFile(filePath)
      .then(() => {
        console.log('scanned');
      })
      .catch(err => {
        console.log(err);
      });
  })
  .catch((err) => {         
      console.log(err);
  })