0

I am building an app that let's the user take a picture or select an image from the camera roll. I want to store a link to that image with @react-native-async-storage/async-storage. When I use react-native-image-picker to select an image or take a photo I get a response like this:

{"fileName": "ECB1469E-6518-43E5-AEEE-7EEAFA38F945.jpg", "fileSize": 9181, "height": 300, "type": "image/jpg", "uri": "file:///var/mobile/Containers/Data/Application/A2B000FA-2393-4D34-9DBC-DE835E3BB3C4/tmp/ECB1469E-6518-43E5-AEEE-7EEAFA38F945.jpg", "width": 400}

And in the documentation it says:

Note on file storage

Image/video captured via camera will be stored in temporary folder so will be deleted any time, so don't expect it to persist. Use saveToPhotos: true (default is false) to save the file in the public photos.

So I assume I cannot just save the uri from the response. Now I wonder how I would get a link to that image in the public photos that I can save and that stays valid even if the temporary folder gets cleared or do I need to copy the file to my apps Document folder?

This is the code I use to let the user take a photo

const options = {
    mediaType: 'photo',
    saveToPhotos: true,
    maxHeight: 300,
    maxWidth: 450,
    quality: 0.3,
  };

  const takePhoto = () => {
    const cb = (request) => {
      console.log(request);
      if (!request.errorCode && !request.didCancel) {
         // save the image link here
      }
    };
    launchCamera(options, cb);
  };```
  • Your question seems like a duplicate of [this one](https://stackoverflow.com/questions/54221671/react-native-image-picker-persistent-storage-after-rebuild). – Dante May 27 '21 at 00:37
  • 1
    I did see that issue but when I use react-native-image-picker it returns a path to the file in the temp folder and not the path to the file in the document folder so I was wondering if I have to copy it over first or if I can rely on the returned path. – Alexander Schad May 28 '21 at 09:43

0 Answers0