ruby-on-rails - 回形针 - 图片上传错误 : "not recognized by the ' identify' command."

标签 ruby-on-rails ruby-on-rails-3 imagemagick paperclip

我使用 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/

相关文章:

unicode - 教 OCR 理解 NSA 和 FISC 修订

jquery - 如何从自动完成中选择 li

ruby-on-rails - Capistrano 3 丢弃 :user variable when executing remote SSH command

ruby-on-rails - ruby rails : How do you add add zeros in front of a number if it's under 10?

ruby-on-rails - Rails 和 Ruby EventMachine 进程之间的通信

ruby-on-rails-3 - 如何在 Rails 中实现 HATEOAS

ruby-on-rails - 仅显示帖子中的一些单词作为预览

php - 使用 imagemagick 自定义字体

imagemagick - 如何使用 ImageMagick 批量添加 Alpha channel ?

ruby-on-rails - 使用SearchKick进行通配符搜索