2010-11-19 96 views
4

我使用Rails 3回形针。我的逻辑允许用户上传图像。这可以正常工作,除非用户选择不是图像的文件。回形针 - 图像上传错误:“不能被'识别'命令识别。”

如果用户选择一个文本文件,例如,验证通行证但与此错误结束:

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. 

至少第一误差指的是该文件类型。但是,如果用户上传一些更具体的文件,像.PXM,然后Rails的行为怪异,并显示此:

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/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. 

有谁知道这是怎么回事?我有下面的代码在我的模型:

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

...这回形针初始化:

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

ImageMagik似乎已安装并正确设置:

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

谢谢!

+1

什么'which identify',''locate_id''或'find/-name identify'返回? – Eric 2010-11-20 02:16:57

+0

$确定 /opt/local/bin/identify – AnApprentice 2010-11-20 02:25:39

+0

我用可卡因0.3.2修正了这个问题。请参阅http://stackoverflow.com/questions/12753157/paperclipnotidentifiedbyimagemagickerror-in-spreeadminimagescontrollercre/12771707#12771707 – 2012-10-07 18:50:05

回答

3

我有与Paperclip和Rails 2.3.8相同的问题。 在您的型号的has_attached_file声明中,为任何非图像文件删除:styles

3

只需将以下代码放在型号上。它不会处理非图像文件。

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