· 6 years ago · Feb 25, 2019, 09:46 AM
1import React, { Component } from "react";
2import {
3 Platform,
4 StyleSheet,
5 Alert,
6 Text,
7 TouchableOpacity,
8 View,
9 Picker,
10 Animated,
11 Easing,
12 Image
13} from "react-native";
14import ImagePicker from "react-native-image-picker";
15import { RNS3 } from "react-native-aws3";
16
17export default class SecondScreen extends Component<Props> {
18 constructor(props) {
19 super(props);
20 this.state = {
21 file: "",
22 saveImages: []
23 };
24 }
25
26 takePic() {
27 const options = {
28 quality: 1.0,
29 maxWidth: 50,
30 maxHeight: 50,
31 }
32 ImagePicker.launchCamera(options,(responce)=>{
33 const file = {
34 uri: responce.uri,
35 name: responce.fileName,
36 method: "POST",
37 path: responce.path,
38 type: responce.type,
39 notification: {
40 enabled: true
41 }
42 };
43 this.state.saveImages.push(file);
44 });
45 }
46 _upload = saveImages => {
47 const config = {
48 keyPrefix: "uploads/",
49 bucket: "s3merahkee",
50 region: "us-east-2",
51 accessKey: "***",
52 secretKey: "***",
53 successActionStatus: 201
54 };
55
56 this.state.saveImages.map(image => {
57 RNS3.put(image, config).then(responce => {
58 console.log(saveImages);
59 });
60 });
61
62 //once after upload is done delete from the gallary
63 };
64 render() {
65 return (
66 <View style={styles.container}>
67 <View style={styles.Camera}>
68 <TouchableOpacity onPress={this.takePic.bind(this)}>
69 <Text>Take Picture</Text>
70 </TouchableOpacity>
71 </View>
72 <View style={styles.Send}>
73 <TouchableOpacity onPress={() => this._upload()}>
74 <Text>Send</Text>
75 </TouchableOpacity>
76 </View>
77 </View>
78 );
79 }
80}