回形针在生产中接受 jpg 和 png [英] paperclip accepting jpg and png on production
问题描述
我在 Rails 应用程序中使用 PaperClip 插件,如下所示:
I'm using PaperClip plugin in my Rails application as follows:
has_attached_file :photo, :styles => {:small => '64X64>', :medium => '250X250>'},
:url => "/assets/user_photos/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/user_photos/:id/:style/:basename.:extension"
# validates_attachment_presence :photo
validates_attachment_content_type :photo, :content_type => ['image/jpeg', 'image/png','image/gif']
validates_attachment_size :photo, :less_than => 1.megabytes
它适用于开发(Mac OSX + Mongrel).但是当我将它投入生产(Linux Debian + Apache/Passenger)时,它只接受 .gif 并且我收到 .png 和 .jpg 的以下错误:
It works fine on development(Mac OSX + Mongrel). But when I put it in production (Linux Debian + Apache/Passenger) it only accepts .gif and I get the following error for .png and .jpg:
Photo /tmp/stream20091028-20066-1t1a0oz-0 is not recognized by the 'identify' command.
Photo /tmp/stream20091028-20066-1t1a0oz-0 is not recognized by the 'identify' command.
我尝试按照一些教程的建议添加以下行,但没有帮助!
I tried adding the following line as some tutorials suggests but it didn't help!
Paperclip.options[:command_path] = "/usr/local/bin"
推荐答案
在您的生产服务器上,尝试运行:
On your production server, try running:
which identify
这应该会为您提供 ImageMagick 识别二进制文件的路径——如果没有,则您没有安装 ImageMagick 或者它不在您的路径中.
This should give you your path to ImageMagick's identify binary -- if it doesn't you don't have ImageMagick installed or it is not in your path.
如果它返回类似/usr/bin/identify"的内容,那么您需要将 production.rb 环境文件中的 Paperclip 选项设置为:
If it returns something like "/usr/bin/identify", then you'll want to set the Paperclip options in your production.rb environment file to:
Paperclip.options[:command_path] = "/usr/bin"
这篇关于回形针在生产中接受 jpg 和 png的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!