By Connor Shea
I’m working on setting up a custom subdomain for my site’s Spaces CDN and was wondering if anyone has any advice on how to get my Rails app to actually return the custom subdomain URL for images instead of the digitaloceanspaces.com domain.
My images are being loaded from https://vglist.sfo2.digitaloceanspaces.com/variants/eK6iXEuKRi1crQgKEvwzMvjj/#{a_bunch_of_other_metadata}, despite my CDN being set up with a subdomain of https://cdn.vglist.co
I have this in my config/storage.yml (it’s called amazon but it’s really DO Spaces):
amazon:
service: S3
access_key_id: <%= Rails.application.credentials.dig(:digitalocean, :access_key_id) %>
secret_access_key: <%= Rails.application.credentials.dig(:digitalocean, :secret_access_key) %>
region: sfo2
bucket: vglist
endpoint: 'https://sfo2.digitaloceanspaces.com'
I tried changing the endpoint but that didn’t seem to work. The custom subdomain is set up and everything, I just need to configure Rails and ActiveStorage to actually use it.
Thanks!
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!
@connoshea Not sure if you’re still in need of a solution to this as the post is rather old, but as I came here via a search, I thought providing one info would be good for posterity.
I’m not aware of anything built in to ActiveStorage as it is quite light in its implementation, so you will have to extend the class for the storage engine that you are using and override some methods to achieve what you want.
This stack overflow post has some details: https://stackoverflow.com/questions/50782477/how-to-add-a-custom-service-to-activestorage
Any update? I want to use Space CDN, but I cann’t find the way to change the url to CDN address.
FYI, the active storage gods have now determined we are worthy of this trivial feature. It’s called “proxying,” and it’s been released in Rails 6.1.0 (December 09, 2020)
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.