A) Send the 'data' to the server as an image binary - this fails because it's not an image binary
B) Include the photo uri in an object and send that as form data to the server - this also fails
render function includes:
<Camera
ref={(cam) => {
this.camera = cam;
}}
style={localStyles.preview}
aspect={Camera.constants.Aspect.fill}
flashMode={Camera.constants.FlashMode.auto}
captureAudio={false}>
<View style = {localStyles.captureBtnContainer}>
<Text
style={localStyles.captureBtn}
onPress={this.takePicture.bind(this)}>
Capture
</Text>
</View>
</Camera>
When the capture button is pressed, the takePicture method is fired - and on success the image should be sent to my server.
takePicture() {
this.camera.capture()
.then((data) => {
this.setState({'photoUri' : data})
var uploadUrl = this.state.uploadUrl;
var photo = {
uri: data,
type: 'image/jpeg',
name: 'photo.jpg',
};
var uploadForm = new FormData()
uploadForm.userKey = this.state.userKey;
uploadForm.append('image', photo);
fetch(uploadUrl, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/related',
},
body: uploadForm
})
.then((response) => response.text())
.then((responseText) => {
alert(responseText);
})
.catch((error) => { alert('takePicture upload: ' + error) });
})
.catch(err => alert('takePicture: ' + err));
}
I expect the 'data' returned to be an image binary - but it doesn't seem to be
Instead the 'data' returned appears to be a uri for the image. This uri, however fails with a "No suitable request handler found for assets-library..."
Version: "master"
FYI - I used the "Mostly automatic install" as opposed to the "manual install" approach.
For anyone experiencing a similar issue I've found that setting:
captureTarget={Camera.constants.CaptureTarget.disk}
Within the
For anyone experiencing a similar issue I've found that setting:
captureTarget={Camera.constants.CaptureTarget.disk}
Within the tag returns a uri usable in the way set out above.
this solution doesnt work
Most helpful comment
For anyone experiencing a similar issue I've found that setting:
captureTarget={Camera.constants.CaptureTarget.disk}Within the tag returns a uri usable in the way set out above.