Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveStorage Feature Request - Support for CDN (Cloudfront) #35926

Closed
eaconway opened this issue Apr 10, 2019 · 7 comments
Closed

ActiveStorage Feature Request - Support for CDN (Cloudfront) #35926

eaconway opened this issue Apr 10, 2019 · 7 comments

Comments

@eaconway
Copy link

Hello Rails team,

**Disclaimer: this is my first Github issue, so apologies if I'm missing something.

I've spent a fair amount of time researching and trialing how to setup Active Storage to leverage Cloudfront. There are a number of issues like:

And even some pieces on other projects:

But can't seem to find a clear solution, or one sanctioned from Rails/Active Storage itself, so I believe this is still a bug. I'm looking for confirmation that this will be resolved in Rails 6 release (hopefully), or feedback from the team. Thanks!

Steps to reproduce

Setup basic rails project with Active storage. Set asset host to Cloudfront CDN (tried pointing CDN to S3 and project, or simply back to project itself). Unfortunately, Active Storage ignores asset_host and pulls directly from S3 regardless.

Expected behavior

When using a CDN to host files for site, specifically those user uploaded through Active Storage, Active Storage should run requests through CDN first when making download requests. Uploads should be through Active Storage current pathways, but once asset_host is set, downloads should flow through CDN.

Actual behavior

Currently, everything flows through Active Storage when trying to download/retrieve blobs, resulting in slow load times

System configuration

Rails version: 5.2.2

Ruby version: 2.5.1

@rafaelfranca
Copy link
Member

Thank you so much for the issue but we don't take feature request on the issue tracker. We recommend you to try to implement the feature and send us a pull request or if you are in doubt if the feature will be accepts ask in Rails Core mailing list for feedback.

@collimarco
Copy link

Any updates on this with Rails 6? We also want to use Cloudfront in front of S3, as recommended by Amazon.

@collimarco
Copy link

Here's my final solution:
https://stackoverflow.com/a/59107484/51387

Basically for now I use sub on service_url.

@joshuacronemeyer
Copy link

Every once in awhile I come back to check on "ActiveStorage CDN support" and google always finds this rails issue. Active development on this can be found here. #34477

@equivalent
Copy link
Contributor

equivalent commented Jul 7, 2021

I've found article where one dude manage to introduce CDN https://lipanski.com/posts/activestorage-cdn-rails-direct-route I've didn't try it yet (will do that in couple of weeks) Just posting it here if anyone find it useful

update

as @joshuacronemeyer recommends in comment bellow https://edgeguides.rubyonrails.org/active_storage_overview.html#putting-a-cdn-in-front-of-active-storage is much better solution

TL;DR I've summed up the CDN solution in https://blog.eq8.eu/til/rails-active-storage-cdn.html

related

@joshuacronemeyer
Copy link

@equivalent Rails active storage docs have a section on using a CDN. https://edgeguides.rubyonrails.org/active_storage_overview.html#putting-a-cdn-in-front-of-active-storage It's probably better to look there.

@zzak
Copy link
Member

zzak commented Jul 10, 2021

See: #42305

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants