首页 > 解决方案 > 无法使用放大将文件从 React Native 上传到 S3

问题描述

我尝试使用以下代码将文件上传到 S3 Bucket

RNFS.readFile(this.state.photo.uri, 'base64').then((res) => {
  Storage.put(filename, base64.decode(res)).then((stored) => {
    console.log('stored', JSON.stringify(stored))
  }).catch(err => {
    console.log(err)
  });
}).catch(err => console.log(err))

它给了我 AWSS3Provider - error uploading [Error: Request failed with status code 403]

但是如果我删除 base64.decode(res) 并运行下面的代码,它会在 S3 上上传一个文件{这个文件没有打开}

RNFS.readFile(this.state.photo.uri, 'base64').then((res) => {
  Storage.put(filename, res).then((stored) => {
    console.log('stored', JSON.stringify(stored))
  }).catch(err => {
    console.log(err)
  });
}).catch(err => console.log(err))

我必须将图像/视频直接从移动应用{React-Native} 上传到 AWS S3。

标签: react-nativeamazon-s3aws-amplify

解决方案


推荐阅读