-
-
Save dce/4e79183a105e415ca0e5e1f1709089b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://viget.com/articles/the-right-way-to-store-and-serve-dragonfly-thumbnails | |
Dragonfly.app.configure do | |
# ... (other settings) | |
define_url do |app, job, opts| | |
thumb = Thumb.find_by_signature(job.signature) | |
if thumb | |
app.datastore.url_for(thumb.uid) | |
else | |
app.server.url_for(job) | |
end | |
end | |
before_serve do |job, env| | |
thumb = Thumb.find_by_signature(job.signature) | |
if thumb | |
throw :halt, [301, { 'Location' => job.app.remote_url_for(thumb.uid) }, [""]] | |
else | |
uid = job.store | |
Thumb.create!(uid: uid, signature: job.signature) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment