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

unlink doesn't delete the picture #352

Closed
BenjaminSchmitt opened this issue Sep 26, 2017 · 18 comments
Closed

unlink doesn't delete the picture #352

BenjaminSchmitt opened this issue Sep 26, 2017 · 18 comments

Comments

@BenjaminSchmitt
Copy link

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 ?

@itinance
Copy link
Owner

I don't know if i got you right. You are deleting an image, right? And the UIImage shows a placeholder then because the image was already deleted? This would be as expected.

@BenjaminSchmitt
Copy link
Author

Thanks for your answer.
So why does the file is still in the gallery ?

@itinance
Copy link
Owner

UIImage will cache Images once it was loaded, even if you remove this file later on physical device.
I don't know how smart UIImage is while recognizing if the original file was removed, that it will also automatically purge the cache. You should work with state to tell the UIimage that the URL is not existing and should render then somehing else.

Anyways, a second call to .exists() should return false instead of true. Have you tried this out?

@BenjaminSchmitt
Copy link
Author

Oh, I didn't think of the cache...

That's it, a second call to the functions returns an error: The file does not exist .
After a reboot, the picture does not appear anymore in the gallery.

Thanks for your help and sorry for my stupid question!

@sp00m
Copy link

sp00m commented Nov 4, 2017

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?

@chad187
Copy link

chad187 commented Nov 19, 2017

I believe I am having a similar issue but I am trying to delete a video. I get the video taken by react-native-camera and then I do this

 if (filepath != null) {
            RNFS.exists(filepath)
            .then( (result) => {
                console.log("file exists: ", result);

      if(result){
        return RNFS.unlink(filepath)
          .then(() => {
            console.log('FILE DELETED');
            RNFS.exists(filepath)
            .then( (result) => {
              console.log("double checked: ", result);
            });
          })
          // `unlink` will throw an error, if the item to unlink does not exist
          .catch((err) => {
            console.log(err.message);
          });
      }

    })
    .catch((err) => {
      console.log(err.message);
    });
  }

I even threw in that extra exists after the unlink to confirm that the file is gone. It throws no errors and the double check even confirms that it can no longer find the file. However, on my Android phone when I go to photos I can still see blank videos there that will play nothing. Furthermore, when I plug the phone into my pc I can find those files. They are taking up space but they cannot be played. They appear to be corrupt. How can I remove these files completely and not just corrupt the content?

@rashmimhatre100
Copy link

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

@cstd
Copy link

cstd commented Apr 21, 2018

+1

@bulats
Copy link

bulats commented Jun 22, 2018

Has this been addressed. Can we reopen this issue?

@0xcodezero
Copy link

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?

@gokul18496
Copy link

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

@matthamil
Copy link

matthamil commented May 13, 2019

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.

@musadiq-jinbade
Copy link

musadiq-jinbade commented Mar 11, 2020

I have to try to unlink to remove image but it storing in the pictures folder, please can #anyone advice

@anjusr
Copy link

anjusr commented Sep 11, 2020

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

@acponciano
Copy link

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.

Gallery and Google Photos remain showing the deleted videos after RNFS.scanFile.

Any other ideas?

@pravinborade
Copy link

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

@yacineyacineyacineyacineyacine

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

@shyammaneks
Copy link

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

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

No branches or pull requests