问题
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);
});
}
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
回答1:
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.
来源:https://stackoverflow.com/questions/54470239/how-to-upload-video-to-s3-using-amplify-or-rnfetchblob