How can I save photo just taken to camera roll


#1

MY CODE

takePicture = async () => {
    if (this.camera) {
      let photo = await this.camera.takePictureAsync({ base64: true })
      FileSystem.moveAsync({
        from: photo.uri,
        to: FileSystem.documentDirectory + 'photos/' + Date.now() + '.png'
      }).catch((error) => {
        console.log(error)
      })
    }
  }

ERROR MESSAGES:

File 'file:///var/mobile/Containers/Data/Application/E0AC92B0-947F-43C0-AAFC-B2CA13017D5C/Library/Caches/ExponentExperienceData/%2540anonymous%252Ftoomuch-d435e834-ce9b-4305-aa47-0dc6823770c6/Camera/14657705-9F18-4F51-A01E-8989CDB73B03.jpg' could not be moved to 'file:///var/mobile/Containers/Data/Application/E0AC92B0-947F-43C0-AAFC-B2CA13017D5C/Documents/ExponentExperienceData/%2540anonymous%252Ftoomuch-d435e834-ce9b-4305-aa47-0dc6823770c6/photos/1525626717492.png'.
- node_modules/react-native/Libraries/BatchedBridge/NativeModules.js:78:57 in <unknown>
- node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:398:4 in __invokeCallback
- ... 4 more stack frames from framework internals

How can i save one photo to camera roll after it’s been taken?


#2

Hey @voyagerone,

You can pass your file uri to the saveToCameraRoll method https://facebook.github.io/react-native/docs/cameraroll.html#savetocameraroll

Cheers,

Adam


#3

Thanks @adamjnav , I has been using this saveToCameraRoll api and it did work. However, the method in my code, I can’t figure out why it was not working. Can you help with that? thanks.


#4

Is there any way to save the file to the file system though rather than directly to the camera roll? It seems Expo FileSystem cannot read the folders camera saves the temp files in.