我初学反应native.I想将文件上传到AWS拍摄照片后使用一次S3反应机摄像头。我能够使用原生的反应相机进行拍照。现在,我需要上传到S3桶。当我寻找,我得到许多文件和我感到困惑,如何使用这个。
我已经做了文件上传到Amazon S3和下载的形式S3使用PHP。但在反应本土,我没有得到如何做到这一点,因为我是一个初学者。我搜索在AWS的S3文件上传文件,在那里我得到了使用PHP,Java和.NET etc..But我没有得到反应本地人。
谁能帮我做到这一点。
我的代码,以图像的原始反应是,
import React, {Component} from 'react';
import {Platform, StyleSheet, Text,TouchableOpacity, View} from 'react-native';
import ImagePicker from 'react-native-image-picker';
import RNS3 from 'react-native-aws3';
export default class App extends Component<Props> {
takePic(){
ImagePicker.showImagePicker({},(responce)=>{
console.log(responce);
const file ={
uri : responce.path,
name : responce.fileName,
type : responce.type,
}
console.log(file);
const config ={
keyPrefix :'uploads/',
bucket : '**',
region :'***',
accessKey:'***',
secretKey :'***',
successActionStatus :201
}
RNS3.put(file ,config)
.then((responce) => {
console.log(responce);
})
})
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>Welcome v</Text>
<TouchableOpacity onPress={this.takePic.bind(this)}>
<Text>Take Picture</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
当我从图库中选择图片/点击新照片的时候给了我下面的错误,
02-05 09:10:52.738 12357 12389 I ReactNativeJS: { uri: '/storage/emulated/0/Pictures/image-cb48f179-5b00-4e0a-93ef-74206f76c4e4.jpg',
02-05 09:10:52.738 12357 12389 I ReactNativeJS: name: 'image-cb48f179-5b00-4e0a-93ef-74206f76c4e4.jpg',
02-05 09:10:52.738 12357 12389 I ReactNativeJS: type: 'image/jpeg' }
02-05 09:10:52.738 12357 12389 E ReactNativeJS: undefined is not an object (evaluating '_reactNativeAws.default.put')
如何解决这个ReactNativeJS:未定义不是对象(评估“_reactNativeAws.default.put”)。
能否请你帮我解决这个问题。
我解决我的错误:) :)。最后,它得到了后4天的工作。很高兴。
我已经安装了反应本地文件上传。现在,它完美的作品。
NPM安装反应本地文件上传--save