amazon-web-services - 如何在 React Native 中直接在 Amazon S3 上上传图片?

标签 amazon-web-services amazon-s3 react-native

我将在 React Native 中将图像上传到 Amazon S3。

我有 S3 signedUrl 用于上传图片。

我如何在 React Native 中使用此 url 上传图片?

如果有人试过这个,请帮助我。

谢谢!

最佳答案

很简单,我花了很多时间才发现:

const xhr = new XMLHttpRequest()
xhr.onreadystatechange = function() {
  if (xhr.readyState === 4) {
    if (xhr.status === 200) {
      // success
    } else {
      // failure
    }
  }
}
xhr.open('PUT', presignedUrl)
xhr.setRequestHeader('Content-Type', fileType)
xhr.send({ uri: filePath, type: fileType, name: fileName })
  • filePath 是文件的完整路径
  • fileType 是文件的 mime 类型
  • fileName为文件名

来源:http://blog.rudikovac.com/react-native-upload-any-file-to-s3-with-a-presigned-url/

关于amazon-web-services - 如何在 React Native 中直接在 Amazon S3 上上传图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36670902/

相关文章:

javascript - AWS elastic beanstalk,在 Django 中提供多个静态文件

python - 以多线程方式从 s3 (boto3) 读取文件

android - 聚焦文本输入时如何处理后退按钮

javascript - React Native Expo - 停留在 "downloading javascript bundle"

android - react native : Compiling Android error on processReleaseResources step

amazon-web-services - 如何使用cloudformation模板获取用户数据的输出值?

json - 如何向 json IAM 策略添加注释?

amazon-web-services - 在集群创建期间自动启动 EC2 上运行脚本

mysql - 如何在 MySQL 中存储图像以及 Amazon S3 中照片的链接?

amazon-web-services - 为什么在公开私钥时使用 Amazon SQS