Skip to content

Instantly share code, notes, and snippets.

@chrise86
Forked from mhayes/migrate_to_s3.rb
Created September 3, 2013 12:35
Show Gist options
  • Save chrise86/6423341 to your computer and use it in GitHub Desktop.
Save chrise86/6423341 to your computer and use it in GitHub Desktop.
# Assuming you've setup Dragonfly to use your local filesystem, here's what you would
# do to get the images over to Amazon S3
# Specify the base path to where images reside on your system
DRAGONFLY_PATH = Rails.root.join("public", "system", "dragonfly", Rails.env)
# Next you'll need to loop over each model that is using dragonfly
SlideRiff.all.each do |riff|
slide_image_file = DRAGONFLY_PATH.join(riff.slide_image_uid)
# check if the file exists on the local filesystem, this allows you to
# run this if new images get added to s3 during the transition phase
if File.exists?(slide_image_file)
# grab the actual image file
file = File.open(slide_image_file)
# tell dragonfly to re-save the image which places the file onto s3
riff.slide_image = file
riff.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment