上传到S3时出现CORS prelfight错误

时间:2015-08-29 23:06:48

标签: amazon-s3 cors

我正在编码https://sendevidence.org并试图让人们直接上传到S3存储桶。我正在

XMLHttpRequest cannot load https://sendevidence-any-agency.s3-us-west-2.amazonaws.com/. The request was redirected to 'https://sendevidence.org/?bucket=sendevidence-any-agency&key=uploads%2Ftest.pdf&etag=%222bb3099f895cbdd3715840357f65f0af%22', which is disallowed for cross-origin requests that require preflight.

上传时。

我的S3斗圈:

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

我的Nginx CORS:

add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

如何删除此错误?文件本身会上传到S3。

1 个答案:

答案 0 :(得分:1)

我通过删除设置来解决问题,以便在成功时执行页面重定向。