Rails ActiveStorageDigitalOcean Spaces CORS

I’m getting a CORS error when trying to upload an image to DigitalOcean Spaces, despite it working fine in development and test.

The error is as follows:

Access to XMLHttpRequest at '' from origin '' 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.


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

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.

Accepted Answer

So I figured out that the reason this wasn’t working is because I needed to set up CORS, and include some headers that Rails/Spaces needed. You need to go your DigitalOcean Spaces settings, then “Add” an Advanced CORS Configuration.

Set the URL to your domain (e.g. for me it’s, then allow PUT/POST (not sure if any others are necessary?). Make sure to set the allowed headers Content-Type, Content-Length, and Content-Md5.

Hopefully that helps! I got stuck on this for a while, so I wanted to create a question and answer it here :)

See also, this issue in the Rails repo: