DO Spaces with React and Rails Active Storage direct upload 403 Forbidden error

Posted September 18, 2018 3.5k views
Ruby on RailsUbuntu 16.04

I’m trying to direct upload to spaces from a ruby on rails api with a react SPA using Rails’ Active Storage and the S3 Service. I’m getting the following response from spaces when attempting to use a signed_url. Thanks in advance.

Response Headers:
Request URL: https://{MyBucket}{REDACTED}?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential={REDACTED}%2F20180918%2Fnyc3%2Fs3%2Faws4_request&X-Amz-Date=20180918T205013Z&X-Amz-Expires=300&X-Amz-SignedHeaders=content-md5%3Bcontent-type%3Bhost&X-Amz-Signature={REDACTED}
Request Method: OPTIONS
Status Code: 403 Forbidden
Remote Address: {ipAddress}:443
Referrer Policy: no-referrer-when-downgrade

Request Headers:
Provisional headers are shown
Access-Control-Request-Headers: content-md5,content-type
Access-Control-Request-Method: PUT
Origin: https://{REDACTED}
Referer: https://{REDACTED
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10136) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3555.0 Safari/537.36

I’ve tried with and without CORS settings and using s3cmd I can read/write to the bucket fine. Please let me know if I need to provide any other information. Thanks!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

This turned out to be a simple CORS issue. I was fixated on the network tab in my browser watching the request get denied. Had I checked out the console tab I would have seen these errors:

OPTIONS https://{REDACTED}{REDACTED}?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential={REDACTED%2F20180919%2Fnyc3%2Fs3%2Faws4_request&X-Amz-Date=20180919T134657Z&X-Amz-Expires=300&X-Amz-SignedHeaders=content-md5%3Bcontent-type%3Bhost&X-Amz-Signature={REDACTED} 
403 (Forbidden)
Access to XMLHttpRequest at 
from origin 'https://{$MY_REACT_APP_URL}' has been blocked by CORS policy: 
Response to preflight request doesn't pass access control check: 
No 'Access-Control-Allow-Origin' header is present on the requested resource.

Taking a look at my original request from the network tab in Chrome I can see that the denied request sent the following headers:

Request Headers:
Access-Control-Request-Headers: content-md5,content-type

Adding a CORS Rule for the $MY_REACT_APP_URL in the above console error with the Allowed headers of content-md5 and content-type took care of this issue.

I also allowed all the methods in the CORS editor and set a max age of 3000 seconds.

  • Did you manage to set rules in DO CORS Configurations?
    I’ve tried several times, but no luck - it just doesn’t save and shows me error message that something went wrong.
    I’m putting my domain, your suggested headers and max age, but it doesn’t work for me.
    Any ideas what could be wrong?

    • @matissg, I did. I just logged in to check my settings and noticed I was getting the “something went wrong” errors when trying to view Spaces. I was able to view it after several tries. It may just be an error with DO’s system. Good luck!