Save camera image in app

#1

How can we save an image in my react native app, clicked by accessing the camera from my react native app.
I intend to use and upload the image in later steps to the server till then I only have to save the clicked image in my react native app.
How can I possibly do this?
Currently I am using this library for accessing the image from my gallery as well as device camera.

Thanks

0 Likes

#2

You could save it to the file system with https://docs.expo.io/versions/v26.0.0/sdk/filesystem.

0 Likes

#3

I tried that, here is my code:
FileSystem.moveAsync({
from: pickerResult.uri,
to: FileSystem.documentDirectory + ‘images/imagename.png’
})

I get the following error:
[Unhandled promise rejection: Error: File ‘file:///data/user/0/host.exp.exponent/cache/ExperienceData/%2540singhalok641%252Fmod/ImagePicker/453428b3-ab61-42bd-bb57-f7d4e9fb442d.jpg’ could not be moved to ‘file:///data/user/0/host.exp.exponent/files/ExperienceData/%2540singhalok641%252Fmod/images/imagename.png’]

Please help

0 Likes

#4

Hey @singhalok641,
Are you sure that the directory images/ exists? You probably need to make such directory, see https://docs.expo.io/versions/v27.0.0/sdk/filesystem#expofilesystemmakedirectoryasyncfileuri-options

0 Likes

#5

Thanks @tsapeta
I tried creating the directory and I get this new error:

Unhandled promise rejection: Error: Directory ‘file:///data/data/host.exp.exponent/cache/ExperienceData/%2540singhalok641%252Fmod/ImagePicker/33af79d3-eeaf-4d42-9139-af272ce4af0a.jpg’ could not be created.

0 Likes

#6

@singhalok641
That error is fine since you’re trying to create a directory at path that already exists (there is a jpg file at this path, the uri is what you received from ImagePicker). Try something like this:

await FileSystem.makeDirectoryAsync(FileSystem.documentDirectory + 'images/')
await FileSystem.moveAsync({
  from: pickerResult.uri,
  to: FileSystem.documentDirectory + ‘images/imagename.png’
})
0 Likes

#7

Thanks @tsapeta
I tried the above same code and I get the same error:

Unhandled promise rejection: Error: Directory ‘file:///data/data/host.exp.exponent/files/ExperienceData/%2540singhalok641%252Fmod/images/’ could not be created.

0 Likes

closed #8

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.

0 Likes