AWSS3Provider上传错误:参数中缺少必需的键“ Bucket”吗?

时间:2019-02-10 11:06:39

标签: amazon-web-services react-native amazon-s3 aws-amplify

我正在使用react-native-image-picker在我的iOS模拟器手机上为我的react native应用获取视频的文件路径。如何使用Amplify将其上传到S3?

import ImagePicker from 'react-native-image-picker';
import RNFetchBlob from 'react-native-fetch-blob';
import {Storage} from 'aws-amplify';

class App extends Component {

 constructor(props) {
    super(props)

 }

  //This function is called on a Button click
  pickVideo = async () => {

     const options = {
     mediaType: 'video'
  };

  ImagePicker.launchImageLibrary(options, (response) => {

    if(response.didCancel){
      console.log('User cancelled image picker');
    }
    else if (response.error){
       console.log('ImagePicker error: ', response.error);
    }
    else{
       this.setState({ 
          vidFileName: response.fileName,
        });

        console.log(response.uri);

       this.putFileInS3(response.path, repsonse.filename);
    }
   });

  }

  readFile = (somefilePath) => {
      return RNFetchBlob.fs.readFile(somefilePath, 'base64').then(data => new 
      Buffer(data, 'base64'));
  } 

  putFileInS3 = (filePath, fileName) => {  

    this.readFile(filePath).then(buffer => {
    Storage.put(fileName, buffer, { contentType: 'video/mp4' })
     .then(() => {console.log('successfully saved to bucket');})
     .catch(e => { console.log(e);});
   }
  }

尽管我从图像选择器获得了响应,但是在尝试上载它时说AWSS3Provider:即使使用IAuth用户使用withAuthenticator登录,参数中也缺少必需的键“ Bucket”。

1 个答案:

答案 0 :(得分:0)

您需要配置存储桶。 https://aws-amplify.github.io/docs/js/storage

上述链接中的一些示例: 1-

sed -re 's/ +([0-9]+) (.+)/\2|\1/'

2-

Storage.configure({
    AWSS3: {
        bucket: '',//Your bucket ARN;
        region: ''//Specify the region your bucket was created in;
    }
});