我刚刚部署了一个rails应用程序,该应用程序使用回形针来处理文件上传到运行apache2,passenger,rails 3.2.3和ruby 1.9.3的Linux ubuntu 10.04服务器。
我的设置在开发中运行良好,但现在在生产中图像永远不会保存。
我已经注释掉了 production.rb 中的以下行,以便 Rails 处理文件上传,并尝试使用和安装 XSendFile。
# Specifies the header that your server uses for sending files
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
和我的照片.rb
attr_accessible :photo_file_name, :photo_file_size, :photo_content_type, :photo, :splash_image
validates_presence_of :photo_file_name, :photo_content_type, :photo_file_size
has_attached_file :photo,
styles: {
thumb: "150x150>"
},
url: "/assets/splash_images/:id/:style/:basename.:extension",
path: ":rails_root/public/assets/splash_images/:id/:style/:basename.:extension"
validates_attachment_size :photo, :less_than => 25.megabytes
validates_attachment_content_type :photo, content_type: /image/
有谁知道会发生什么?非常感谢
如果默认路径上未安装 ImageMagick,则需要指定路径。对于 Windows 用户,请在初始值设定项/paperclip.rb 中执行以下操作:
需要"回形针"需要"rbconfig"is_windows = (RbConfig::CONFIG['host_os'] =~/mswin|mingw|cygwin/)
回形针选项[:command_path] = 'C:\ImageMagick' 如果is_windows 回形针选项[:swallow_stderr] = 假
在你的ImageMagick路径中找到"识别"的位置,并将其放在这里。当然,你需要把 linux 路径放在那里。(/usr/bin/...)
感谢梅杜扎和雨果为我指明了正确的方向。为了成功上传和保存图像,我必须在 linux 服务器上安装 Imagemagick,并授予对图像路径的写入权限,如下所示:
如果不从根运行,则附加 sudo
apt-get install imagemagick
apt-get install libmagick9-dev
gem install rmagick
chmod -R 777 app/app_name/public/assets/image_folder