Tim Clemans
Tim Clemans

Reputation: 935

CORS prelfight error when uploading to S3

I'm coding https://sendevidence.org and trying to allow people to upload straight to an S3 bucket. I'm getting

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.

when uploading.

My S3 bucket cors:

<?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>

My 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';

How can I remove this error? The files themselves do get uploaded to S3.

Upvotes: 2

Views: 358

Answers (1)

Tim Clemans
Tim Clemans

Reputation: 935

I resolved the problem by removing the setting to do a page redirect on success.

Upvotes: 1

Related Questions