Skip to content

Instantly share code, notes, and snippets.

@parndt
Created May 7, 2010 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parndt/393047 to your computer and use it in GitHub Desktop.
Save parndt/393047 to your computer and use it in GitHub Desktop.
# bulk upload images to refinery
# open script/console on refinery site
# > script/console
# define some functions we need
include ActionController::TestProcess
def use_temp_file(fixture_filename)
temp_path = File.join('/tmp', File.basename(fixture_filename))
FileUtils.mkdir_p File.join('/', 'tmp')
FileUtils.cp File.join('/', fixture_filename), File.join('/', temp_path)
yield temp_path
ensure
FileUtils.rm_rf File.join('/', 'tmp')
end
# now upload the images
(imgs = Dir["/images/**/*"]).each do |img|
a = use_temp_file(img) do |file|
att = Image.create :uploaded_data => fixture_file_upload(file, `file -Ib "#{img}"`.split(';').first)
att.reload unless att.new_record?
att
end
a.save if a.new_record?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment