缺少什么CredentialsError:配置中缺少凭据?

时间:2020-05-08 23:08:30

标签: amazon-web-services react-native amazon-s3 amazon-cognito aws-sdk-js

我正试图允许我的用户将其文件上传到S3存储桶中。为了实现这一点,我正在使用AWS Cognito,因此每次他们尝试上载文件时,它们都会收到临时密钥。我的上传看起来像这样:

const results = await DocumentPicker.pick({
        type: [DocumentPicker.types.audio],
      })


        AWS.config.region = 'us-west-1'
        AWS.config.credentials = new AWS.CognitoIdentityCredentials({
          IdentityPoolId: 'us-west-1:....',
          RoleArn: 'roleValue...',
        })

        const s3 = new AWS.S3({
          apiVersion: '2006-03-01',
          params: { Bucket: 'bucketName' },
        })

        const base = await fs.readFile(results.uri, 'base64')
        const buffer = base64.decode(base)
        var uploadParams = {
          Bucket: 'bucketName',
          Key: `dir1/id/filename`,
          Body: buffer,
        }
        s3.upload(uploadParams, (err: Error, data: ManagedUpload.SendData) => {
          if (err) {
            console.warn('callback error')
            console.warn(err)
          } else {
            console.warn(data)
          }
        })

缺少什么?我是否忽略了某些事情或还有其他事情要做?

0 个答案:

没有答案