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

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 10_13_6) 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!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.