【问题标题】:CORS prelfight error when uploading to S3上传到 S3 时出现 CORS 预检错误
【发布时间】:2015-11-24 07:48:12
【问题描述】:

我正在编写 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。

【问题讨论】:

    标签: amazon-s3 cors


    【解决方案1】:

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

    【讨论】:

    • 感谢您回答自己的问题!
    猜你喜欢
    • 2019-04-18
    • 2020-12-04
    • 2022-01-04
    • 2021-12-11
    • 2020-03-31
    • 2018-09-19
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    相关资源
    最近更新 更多