Reputation: 817
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));
}
Upvotes: 1
Views: 3786
Reputation: 158
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>
Upvotes: 3
Reputation: 3150
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!
Upvotes: 1