Paperclip images failing to save in production rails

六眼飞鱼酱① 提交于 2019-12-11 19:13:44

问题


Im have just deployed a rails app which uses Paperclip to handle the file uploads to a linux ubuntu 10.04 server running apache2, passenger, rails 3.2.3 and ruby 1.9.3.

My setup worked perfectly fine in development, however now in production images never save.

i have commented out the following lines in production.rb so that rails deals with the file uploads and also tried using and installing 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

and my picture.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/

Does anyone know what could be going on? many thanks


回答1:


You need to specify paths if ImageMagick is not installed on the default paths. For windows users, do something like this in initializers/paperclip.rb:

require "paperclip" require 'rbconfig' is_windows = (RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/)

Paperclip.options[:command_path] = 'C:\ImageMagick' if is_windows Paperclip.options[:swallow_stderr] = false

find the location of "identify" in your imagemagick path and put that in here. Of course, you need to put the linux path in there. (/usr/bin/ ...)




回答2:


Thanks Meduza and Hugo for pointing me in the right direction. To get the images uploading and saving successfully I had to install Imagemagick on the linux server and also give write permissions to the image path like so:

Append with sudo if not running from root

 apt-get install imagemagick
 apt-get install libmagick9-dev
 gem install rmagick

 chmod -R 777 app/app_name/public/assets/image_folder


来源:https://stackoverflow.com/questions/12800375/paperclip-images-failing-to-save-in-production-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!