我使用 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
谢谢!
最佳答案
我在 Paperclip 和 Rails 2.3.8 上遇到了同样的问题。
在您模型的 has_attached_file
声明,删除 :styles
对于任何非图像文件。
关于ruby-on-rails - 回形针 - 图片上传错误 : "not recognized by the ' identify' command.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4222454/