如何使用Amplify或RNFetchBlob将视频上传到S3? [英] How to upload video to S3 using Amplify or RNFetchBlob?
问题描述
我正在使用react-native-image-picker
在我的iOS模拟器手机上为我的react native应用获取视频的文件路径.如何使用Amplify将其上传到S3?
I'm using react-native-image-picker
to get a file path of a video on my iOS simulator phone for my react native app. How do i use this to upload to S3 using Amplify?
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应用程序中上传图像"部分.但是也许我错过了什么?你能帮忙吗?
I am trying to follow this: https://aws-amplify.github.io/docs/js/storage, in the Upload an image in React Native app section. But maybe i've missed something? Can you help please?
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
推荐答案
This package works perfectly to send data to your bucket in S3, react-native-aws3.
如果您在使用该软件包时需要任何帮助,请发表评论.
If you want any assistance in using the package, do comment.
这篇关于如何使用Amplify或RNFetchBlob将视频上传到S3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!