· 8 years ago · Dec 24, 2017, 11:24 PM
1import {RNS3} from "react-native-aws3";
2
3class NCamera extends React.Component {
4 takePicture() {
5 this.camera.capture()
6 .then((data) => {
7 const file = { uri: data.path, name: 'image.png', type: 'image/png',}
8 const options = {
9 keyPrefix: "images/",
10 bucket: "my-bucket-name",
11 region: "us-east-1",
12 accessKey: "key",
13 secretKey: "secret-key",
14 successActionStatus: 201
15 }
16 RNS3.put(file, options)
17 .then(response => {
18 if (response.status != 201 )
19 console.log('Error uploading file to S3');
20 else
21 console.log(response.body);
22 })
23 .catch (error => console.log(`Error uploading: ${error}`));
24 })
25 .catch(err => console.log(err));
26 }
27 render() {
28 return (
29 <Camera
30 ref={(cam) => {
31 this.camera = cam;
32 }}
33 style={styles.preview}
34 aspect={Camera.constants.Aspect.fill}>
35 <Text style={styles.capture} onPress={this.takePicture.bind(this)}>[CAPTURE]</Text>
36 </Camera>
37 );
38 }
39}