Created
May 7, 2010 04:15
-
-
Save parndt/393047 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
# 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