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

Allow overriding filename in Blob#service_url #31650

Merged
merged 1 commit into from Jan 8, 2018

Conversation

rosa
Copy link
Member

@rosa rosa commented Jan 8, 2018

Summary

This is a simple change that allows a filename to be passed to Blob#service_url, in the same way as expires_in and disposition.

Other Information

This is useful when we have several representations that share the same underlying file, each one with a different name, and we need to provide a different download URL based on that name instead of using the file's, for each of them.

r? @georgeclaghorn

This is useful when we have several representations for the same
underlying file, each one with a different name, and we need to provide
a custom download URL based on that name and not that of the underlying
file.
@rails-bot
Copy link

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.

@@ -201,7 +201,7 @@ def representable?
# with users. Instead, the +service_url+ should only be exposed as a redirect from a stable, possibly authenticated URL.
# Hiding the +service_url+ behind a redirect also gives you the power to change services without updating all URLs. And
# it allows permanent URLs that redirect to the +service_url+ to be cached in the view.
def service_url(expires_in: service.url_expires_in, disposition: :inline)
def service_url(expires_in: service.url_expires_in, disposition: :inline, filename: self.filename)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the simplest version I came up with, that assumes a ActiveStorage::Filename instance here. I was thinking that a string could also be allowed, and then do:

service.url ... filename: ActiveStorage::Filename.new(filename.to_s)

Or implement something like ActiveStorage::Filename#wrap and save doing the conversion twice in the default case:

service.url ... filename: ActiveStorage::Filename.wrap(filename)

@georgeclaghorn georgeclaghorn merged commit edcd32e into rails:master Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants