Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
namespace :images do
desc "converts blob to paperclip"
task :convert => :environment do
Image.find_each do |i|
puts i.id
tmp_file = File.dirname(__FILE__) + "/../../tmp/file.#{i.mime.gsub(/image\//,'')}"
File.open(tmp_file,'w') do |f|
f.write(i.data)
end
File.open(tmp_file,'r') do |f|
i.file = f
i.save!
end
end
end
end
@webficient
Owner

Assuming you have an Image model with a blob field called "data":

  1. Add Paperclip fields to your model.
  2. Save the above as a rake task inside your Rails app's lib/tasks.
  3. In line 12, the "file" attribute should be changed to match the attribute used in "has_attached_file :file"
  4. Run rake images:convert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.