Save Image into app from camera roll

#1

Hi

Is it possible to pick an image using ImagePicker but then save it in the app that I’m using and not in camera roll? And every time I open the app I’ll be able to see the saved image (SQlite)?

0 Likes

#2

hey! I believe ImagePicker lets you choose pictures already saved on your devices camera roll, so I don’t quite understand what you mean by not saving an image into the camera roll.

when you pick something using ImagePicker, it will store the photo in the apps cache (FileSystem.cacheDirectory + 'ImagePicker/' directory ), and you can then save that in sqlite or onto the apps permanent storage, and you’ll be able to use it.

more about FileSystem

0 Likes

#3

Hi Samee thanks for reply, what I mean is to pick an image from camera roll and save it into SQlite or onto apps permanent storage (and I if delete it that image from camera roll it will be still in the app),

I don’t know know how to do it. So far I got to this point where I can pick an image but then I don’t know how to save it into apps permanent storage. Do you know how to ?

  _pickImage = async () => {
    let result = await ImagePicker.launchImageLibraryAsync({
      allowsEditing: true,
    });

    console.log(result);

    if (!result.cancelled) {
      this.setState({ image: result.uri });
    }
  };
0 Likes

#4

Ah, ok. It doesn’t look like you can overwrite the location the file is saved to with ImagePicker right now. Maybe you could copy or move the file to your db or permanent storage after you select it.

How to move a file

basically I would do something like:

FileSystem.moveAsync({
    from: result.uri,
    to: FileSytem.documentDirectory + 'images/imagename.png'
})

(you probably have to create the new directory first)

0 Likes

#5

If you’re interested, I made a module that makes it really easy to debug this kind of filesystem stuff (Only works on iOS right now, some functionality is being added to Filesystem for android). Basically lets you look at your apps cache and permanent storage in a clickable folder viewer.

Hope it helps!

0 Likes

#6

Thanks for info samee, I solved the problem by storing base64 image into SQlite, then render all images trough array. Thank you again

1 Like

#7

clever. nice work man!

0 Likes