By jtsmith
I’m using Active Storage in a Rails 6 application with Spaces. I use “local” file storage for development and Spaces for production. I’d like to use the Spaces CDN feature, which I believe is possible with Active Storage “proxying” the files, but am unsure how to implement it. I’m unable to find a solid tutorial. I’ve followed tutorials suggesting “direct” routes for the CDN, but that doesn’t seem to work if you have different storage locations for different environments. Can anyone point to some setup instructions?
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!
Heya,
Just came across this answer and decided to write some general guidelines for anyone who comes across this in the future despite the old question.
You’re right in that Active Storage can be used with Spaces. The CDN feature can also be enabled, but the implementation can depend on your specific use case and environment setup.
For handling different storage locations for different environments, you might have to tailor your configuration accordingly. That could involve setting different service configuration in each environment’s specific storage.yml file. So your production file would point to the Spaces service, while the development file would point to local storage.
As for the CDN setup, you will need to make sure that the CDN is enabled on your Spaces bucket and then use the CDN endpoint as the base URL for your ActiveStorage service.
There seems to be some ambiguity in the existing tutorials, unfortunately. You may find DigitalOcean’s documentation on this topic helpful, where the use of Spaces with Ruby on Rails is explained: Using Spaces with Ruby on Rails
Please remember that these instructions are general guidance and may need to be adapted to your specific setting.
Hope that this helps!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.