TemporaryRedirect错误从反应本机上传图像到AWS S3

时间:2017-05-19 06:29:17

标签: javascript reactjs amazon-web-services amazon-s3 react-native

通过react-native-aws3将图像上传到AWS S3,我得到了此回复(图片是我的redux dev工具的屏幕截图):enter image description here

我正在使用这个redux-observable史诗:

export const uploadImageEpic = action$ =>
  action$.ofType(UPLOAD_IMAGE)
    .mergeMap(action =>
      Observable.fromPromise(
        RNS3.put(action.payload.file, action.payload.options)
      )
        .map(response => uploadImageFulfilled(response))
        .catch(error => {
          return Observable.of(uploadImageRejected(error.xhr.response))
        })
    )

action.payload.file就是这个(从chrome控制台复制的对象):

name: "image-5a430850-8314-497e-8d56-0df45e3fed95.jpg"
type: "image/png"
uri: "file:///storage/sdcard/Android/data/com.vepo/files/Pictures/image-5a430850-8314-497e-8d56-0df45e3fed95.jpg"

选项(从chrome控制台复制的对象):

accessKey: "cant really give this away"
bucket: "vepo-images"
region: "ap-southeast-2"
secretKey: "cant really give this away"
successActionStatus: 201

所以无论如何我应该再次尝试到另一个端点。所以我将它添加到选项对象:url: 'vepo-images.s3-ap-southeast-2.amazonaws.com',我从AWS得到了完全相同的响应。还尝试了s3-ap-southeast-2.amazonaws.com作为网址。

知道我应该怎么做吗?

我的桶的CORS配置:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>DELETE</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
    <AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
</CORSConfiguration>

铲斗政策:

{
  "Id": "Policy1495174705604",
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1495174695734",
      "Action": "s3:*",
      "Effect": "Allow",
      "Resource": "arn:aws:s3:::vepo-images/*",
      "Principal": "*"
    }
  ]
}

编辑:它现在有效,没有做任何改动。两者都没有url添加到option对象和url: 's3-ap-southeast-2.amazonaws.com。所以也许AWS S3 API有点气质......这可能是一个问题。我想我会抓住307并重试,将url param切换进options进出。

1 个答案:

答案 0 :(得分:0)

您应该可以为您可能正在使用的HTTP客户端配置followRedirects = true。

现在它的307,可能是302以后,如果AWS确实疯了,那就是301。