【问题标题】:AWSS3Provider uploading error: Missing required key 'Bucket' in params?AWSS3Provider 上传错误:参数中缺少必需的键“桶”?
【发布时间】:2019-02-10 11:06:38
【问题描述】:

我正在使用 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: Missing required key 'Bucket' in params,即使用户使用 withAuthenticator 以 IAM 用户身份登录。

【问题讨论】:

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


    【解决方案1】:

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

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

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

    2 -

    import Amplify from 'aws-amplify';
    
    Amplify.configure({
        Auth: {
            identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab', 
            region: 'XX-XXXX-X', // REQUIRED - Amazon Cognito Region
            userPoolId: 'XX-XXXX-X_abcd1234', //OPTIONAL - Amazon Cognito User Pool ID
            userPoolWebClientId: 'XX-XXXX-X_abcd1234', 
        },
        Storage: {
            AWSS3: {
                bucket: '', //REQUIRED -  Amazon S3 bucket
                region: 'XX-XXXX-X', //OPTIONAL -  Amazon service region
            }
        }
    });
    

    【讨论】:

    • 嗨,Fabio,这些包含在哪里(例如 App.js 或其他文件)?我只是担心确保它是安全的。
    • 我很确定我是用 CLI 自动设置的,所以可能不需要上面的手动配置。我的“aws-exports.js”应该是什么样的?
    猜你喜欢
    • 2019-01-14
    • 2017-06-04
    • 2022-01-01
    • 2021-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-09
    相关资源
    最近更新 更多