Skip to content

Instantly share code, notes, and snippets.

@dce dce/dragonfly_config.rb Secret
Last active Jun 29, 2018

Embed
What would you like to do?
# 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
You can’t perform that action at this time.