我正在使用react-native-image-picker
在我的iOS模拟器手机上为我的react native应用获取视频的文件路径。如何使用Amplify将其上传到S3?
import ImagePicker from 'react-native-image-picker';
import RNFetchBlob from 'react-native-fetch-blob';
class App extends Component {
constructor(props) {
super(props)
this.state = {
vidFileName: '',
fileURI: '',
}
this.putFileInS3 = this.putFileInS3.bind(this);
}
pickVideo = async () => {
const options = {
mediaType: 'video'
};
ImagePicker.launchImageLibrary(options, (response) => {
console.log('Response = ', response);
this.setState({
vidFileName: response.fileName,
fileURI: response.uri,
});
this.putFileInS3();
}
}
readFile = (somefilePath) => {
return RNFetchBlob.fs.readFile(somefilePath, 'base64').then(data => new
Buffer(data, 'base64'));
}
putFileInS3 = async () =>
{
RNFetchBlob.fs.readFile(this.fileURI).then(buffer => {
Storage.put(vidFileName, buffer, { contentType: 'video/mp4' })
conole.log('successfully uploaded video to bucket');
}).catch(e => {
console.log(e);
});
}
我正在尝试遵循以下操作:https://aws-amplify.github.io/docs/js/storage,在“在React Native应用程序中上传图像”部分。但是也许我错过了什么?你能帮忙吗?
Error: file:///Users/xxxxxxxxxx/Library/Developer/CoreSimulator/Devices/xxxxxxxxx/data/Containers/Data/Application/5CxxxxxxxxxxxxxC79/tmp/4xxxxxxxxxxxxxx.MOV . <-URI
App.js:130 Error: file not exists
at createErrorFromErrorData (NativeModules.js:146)
at NativeModules.js:95
at MessageQueue.__invokeCallback (MessageQueue.js:397)
at MessageQueue.js:127
at MessageQueue.__guard (MessageQueue.js:297)
at MessageQueue.invokeCallbackAndReturnFlushedQueue (MessageQueue.js:126)
at debuggerWorker.js:72
答案 0 :(得分:0)
此软件包非常适合将数据发送到S3 react-native-aws3中的存储桶。
如果在使用该软件包时需要任何帮助,请发表评论。
答案 1 :(得分:0)
putFileInS3 = async () => {
RNFetchBlob.fetch('PUT', link,
{
'Content-Type': undefined
},
RNFetchBlob.wrap(Platform.OS === "android" ? this.state.fileURI :
this.state.fileURI.replace("file://", "")))
.then((resp) => {
this.onImageUploadSuccess(resp)
}).catch((err) => {
this.onUploadFailure(err)
})
}