Rails / Clip using the command line

I have a bunch of jpeg files in a folder on my server, and I'm trying to attach them to their respective instances Propertyusing the rake command.

property.rb has the following code:

  has_attached_file :temp_photo,
    :styles => PropertyImage::STYLES,
    :url => "/assets/:class/:attachment/:id_partition/:style_:basename.:extension",
    :path => "#{Rails.root}/public/assets/:class/:attachment/:id_partition/:style_:basename.:extension"

I use paperclip for other models and there are no problems, but I have a problem when I try to do the following:

p = Property.find(id)
file = File.open(temp_file_path)
p.temp_photo = file
p.save

# => false

file.close
p.errors

# => "/tmp/stream20110524-1126-1cunv0y-0.jpg is not recognized by the 'identify' command."

The file definitely exists, and I tried to change the permissions. Restarting the server does not help. The problem seems to be related to using the command line, as the normal form / HTTP method works fine. This is only a temporary setup, so I'm looking for an efficient way to import a package of files into my rails paperclip model.

Any suggestions?

+3
source share
1 answer
path = 'target_file_path'
attach_name = 'temp_photo'

p = Property.find(id)
attach = Paperclip::Attachment.new(attach_name, p, p.class.attachment_definitions[attach_name.to_suym])

file = File.open(path) 
attach.assign file
attach.save

file.close
+4

All Articles