纸片 - 图像上传错误:“未被'identify'命令识别。”

4
我使用Rails 3paperclip。我的逻辑允许用户上传图像。这很好,除非用户选择的文件不是图像。
例如,如果用户选择了一个文本文件,则验证通过但最终会出现以下错误:
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/"

ImageMagick似乎已经安装并正确设置:

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

谢谢!


1
which identifylocate identifyfind / -name identify会返回什么? - Eric
$ which identify /opt/local/bin/identify - AnApprentice
我用 Cocaine 0.3.2 修复了这个问题。请查看 https://dev59.com/sWnWa4cB1Zd3GeqPykKJ#12771707。 - Leo Lukin
请查看此链接:https://dev59.com/sWnWa4cB1Zd3GeqPykKJ#12771707 - Leo Lukin
2个回答

3
我在使用Paperclip和Rails 2.3.8时也遇到了同样的问题。 在你的模型的has_attached_file声明中,对于任何非图像文件,请删除:styles

3
只需将以下代码放在模型上即可。它不会处理非图像文件。
before_post_process :image?
def image?
  !(data_content_type =~ /^image.*/).nil?
end

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接