Search code examples
javascriptexpoexpo-image-picker

How to delete photo using Expo Image Picker?


I have a project with Expo Image Picker. When taking a photo, I save the path to my database, and the photo is recorded in some local cache of the program. I have a function to delete a row from the database, but I would like to delete the photo from the phone as well. How to do it with Expo Image Picker for Android and IOS?

Also how long are these photos stored on the phone? I want them to stay there until I manually delete them.

I did not find anything about that in the official documentation.


Solution

  • i think you can use deleteAsync method of expo-file-system to delete the cached file, as

    ...
    import * as FileSystem from 'expo-file-system';
    ....
    await FileSystem.deleteAsync(yourFileUri, { idempotent: true });
    // if 'idempotent' is set to true, no error thrown in case file doesn't exist
    ...
    

    where yourFileUri is the URI of the file you get from ImagePicker.launchImageLibraryAsync method