waynehoover / s3_direct_upload

Direct Upload to Amazon S3 With CORS
MIT License
652 stars 333 forks source link

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://eu-west-1.amazonaws.com/duk-assets-uat/. (Reason: CORS request did not succeed). #271

Closed LimeBlast closed 5 years ago

LimeBlast commented 5 years ago

I've inherited a project from another dev which uses this gem. It used to work fine, but we've recently updated Rails from 4.2 to 5.0 (in an effort to take it all the way to 5.2), and it's stopped working.

The error we get when trying to use the form is:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://eu-west-1.amazonaws.com/duk-assets-uat/. (Reason: CORS request did not succeed).[Learn More]

We've checked the CORS setting on the bucket, and they're correct so far as we can tell:

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

My config looks like this:

S3DirectUpload.config do |c|
  c.access_key_id     = 'MY_ACCESS_KEY'
  c.secret_access_key = 'MY_SECRET_ACCESS_KEY'
  c.bucket            = 'duk-assets-uat'
  c.region            = 'eu-west-1'
end

So I'm all out of ideas. Can anyone help? Thanks.

LimeBlast commented 5 years ago

I think I've fixed the issue, I added the following to the config block:

c.url               = "https://#{c.bucket}.s3.amazonaws.com/"