开发者

Paperclip - Image Uploading Error: " not recognized by the 'identify' command."

I use Rails 3 and paperclip. My logic allows user to upload an image. That works fine unless the user selects a file that is not an image.

If the user picks a text file, for instance, validation passes but ends up with this error:

5 errors prohibited the profile update:

Profile pic content type is not one of image/jpeg, image/png, image/gif
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-17xuiu4-0.js is not recognized by the 'identify' command.
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-17xuiu4-0.js is not recognized by the 'identify' command.
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-17xuiu4-0.js is not recognized by the 'identify' command.
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-17xuiu4-0.js is not recognized by the 'identify' command.

At least the first error refers to the file type. But if the user uploads some more specific file, like a .PXM, then Rails behaves strange and shows this:

4 errors prohibited the profile update:

Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-1scwkg7-0.pxm is not recognized by the 'identify' command.
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-1scwkg7-0.pxm is not recognized by the 'identify' command.
Profile pic /var/folders/l开发者_C百科F/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-1scwkg7-0.pxm is not recognized by the 'identify' command.
Profile pic /var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20101118-229-1scwkg7-0.pxm is not recognized by the 'identify' command.

Does anyone know what's going on here? I have the following code in my model:

validates_attachment_content_type :profile_pic, :content_type=>['image/jpeg', 'image/png', 'image/gif']

...and this paperclip initializer:

Paperclip.options[:command_path] = "/opt/local/bin/"

ImageMagik appears to be installed and set up correctly:

$ which Magick-config
/opt/local/bin/Magick-config

Thanks!


I had the same problem with Paperclip and Rails 2.3.8. In your Model's has_attached_file declaration, remove the :styles for any non-image files.


Just put the code below on model. It will not process non-image file.

before_post_process :image?
def image?
  !(data_content_type =~ /^image.*/).nil?
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜