How to upload video to S3 using Amplify or RNFetchBlob?

我的梦境 提交于 2019-12-11 17:55:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!