Paperclip images failing to save in production rai

2019-08-16 16:45发布

问题:

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