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

Active storage add proxying and direct downloads #34477

Open
wants to merge 61 commits into
base: master
from

Conversation

Projects
None yet
6 participants
@fleck
Copy link

fleck commented Nov 17, 2018

Summary

Added the option to globally change how active storage files are delivered. Users can now set app.config.active_storage.delivery_method to [*:redirect, :proxy, :direct]. There's also the option to override at the model level using has_one_attached :avatar, delivery_method: :proxy syntax.

This is just a rough draft, still could be DRYed up a bit, needs tests, and documentation. Just want to get some feedback before I go to far.

Other Information

If you are updating any of the CHANGELOG files or are asked to update the
CHANGELOG files by reviewers, please add the CHANGELOG entry at the top of the file.

Finally, if your pull request affects documentation or any non-code
changes, guidelines for those changes are available
here

@rails-bot

This comment has been minimized.

Copy link

rails-bot commented Nov 17, 2018

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @georgeclaghorn (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@rails-bot rails-bot bot added the activestorage label Nov 17, 2018

@fleck

This comment has been minimized.

Copy link
Author

fleck commented Jan 11, 2019

Still working on it, my son was born 👶 on December 19th so that’s slowed my progress a little 😀 but I just added the documentation last week and I’m going to try and finish writing tests this weekend

@rails-bot rails-bot bot added docs railties labels Jan 15, 2019

@ConfusedVorlon

This comment has been minimized.

Copy link
Contributor

ConfusedVorlon commented Jan 15, 2019

I'm not qualified to review the code - but as a future user: this looks great. Thank you.

@fleck

This comment has been minimized.

Copy link
Author

fleck commented Jan 20, 2019

I've been using for some production apps and the results are great! For example, https://idealguides.com/1998-Suzuki-DR200SE has a 168 KB image that now downloads in 43 ms! This image used to take about 500ms with the old redirect method. Best part, if you're a Cloudflare user, simply setting delivery_method: :proxy at the model is all that's needed to take advantage of the speed improvement! I have this backported to rails 5 https://github.com/fleck/rails/tree/active-storage-backport-proxy-and-direct-downloads-to-rails-5 in case you have an application that can't run on rails 6. Would love for this to make it into the upcoming rails 6 release, but haven't heard from any maintainers yet.

@fleck

This comment has been minimized.

Copy link
Author

fleck commented Jan 20, 2019

This PR also has the advantage of allowing users to change assets from semi-private redirects to public via proxy without having to re-upload images or mess around with your storage providers settings!

@georgeclaghorn

This comment has been minimized.

Copy link
Member

georgeclaghorn commented Jan 20, 2019

Sorry for the delay, @fleck. This PR is on my list and I’ll get back to you as soon as I can.

@EnziinSystem

This comment has been minimized.

Copy link

EnziinSystem commented Jan 30, 2019

@fleck
How to check your code?
I am looking for the solution use Active Storage with CDN service.

@fleck

This comment has been minimized.

Copy link
Author

fleck commented Feb 2, 2019

@EnziinSystem
if you want to try it out with a rails 5 application I have a backport that you can use like this:
gem 'rails', git: 'https://github.com/fleck/rails.git', ref: '6a75cc02c6372acc5f919c57fd62b852513c6aa9'

if you have rails 6 compatible application you can use it like this

gem 'rails', git: 'https://github.com/fleck/rails.git', ref: 'ddbe958df7d43e4c8bbe614b8559cedf25cb8240'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment