1

I am using react-native-camera in my react-native app and everything works well, however when I take a photo the picture saves on my device which I do not want, the image is supposed to be sent to an api but NOT saved on my device, anyone know how I can get it to not save on the device?

render() {
return(
  <View style={styles.container}>
    <Camera
      style={styles.camera}
      ref={ref => {this.camera = ref;}}
      type={Camera.constants.Type.back}
      flashMode={Camera.constants.FlashMode.on}
      orientation={Camera.constants.Orientation.landscapeLeft}>
      <TouchableOpacity onPress={this.takePicture.bind(this)} style={{zIndex: 100}}>
        <View style={styles.cameraButton}></View>
      </TouchableOpacity>
    </Camera>
  </View>
  );
}

takePicture()
{
  this.camera.capture()
  .then((data) => this.sendData(data))
  .catch(err => console.error(err));
}
random1234
  • 777
  • 3
  • 17
  • 41

2 Answers2

3

The correct answer is Edit #2!

You can open an issue at our repo: https://github.com/react-native-community/react-native-camera

The image is saved in your app's cache directory.

When the promise is resolved, the object contains an uri, the path to the image. Or you can pass the option base64: true, to receive the base64 representation of your image from the takePictureAsync promise.

With the base64 string, you can send it to your server. That is what we do in our apps.

Edit: if you really do not want it saved in your app's cache directory, we could create an option in the takePictureAsync method to do it. Feel free to open an issue about this in our repo as a feature request.

Edit #2: Correct answer: You are using RCTCamera, which saves the image on the device by default.

Use the prop captureTarget, passing the value Camera.constants.CaptureTarget.temp. So:

<Camera
...
captureTarget={Camera.constants.CaptureTarget.temp}
...
</Camera>
jgfidelis
  • 158
  • 1
  • 7
  • Hello, thank you for the answer, opening an issue would seem like a good idea, however I really need to get this fixed this week, is there no way to not have it saved currently? Will the base64 thing that you mentioned do that? And how would I do it? – random1234 Apr 09 '18 at 07:00
1

You could use this API, I use it and is so easy to send images.

https://github.com/react-community/react-native-image-picker

You avoid the work of create a Camera view and when you choose the photo (or take the photo) you get data of it to send where you want!

SmoggeR_js
  • 2,950
  • 4
  • 22
  • 52
  • 1
    My problem is not that I can't use the photo, I am already doing that and sending it to an api, all that is done, what my question was, is that I don't want the photos to get saved to my device, do you know how I could accomplish that? – random1234 Apr 09 '18 at 07:02