Report this

What is the reason for this report?

Rails ActiveStorageDigitalOcean Spaces CORS

Posted on April 13, 2019

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 'https://vglist.sfo2.digitaloceanspaces.com/KaRtoiMSiLxFpJGQHg8ZrXrC' from origin 'https://vglist.co' 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.



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!

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.

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 https://vglist.co, 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: https://github.com/rails/rails/issues/32581

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.