Paperclip image uploads in Rails - Paperclip::CommandNotFoundError
I'm using paperclip to handle image uploads to rails. it worked fine on my dev OSX machine, but now on my web server I get this error:
[paperclip] /Users/marky/bin/identify '-format' '%wx%h' '/tmp/stream,16451,2.JPG[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::CommandNotFoundError: Paperclip::CommandNotFoundError>
[paperclip] /Users/marky/bin/identify '-format' '%wx%h' '/tmp/stream,16451,2.JPG[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::开发者_开发百科CommandNotFoundError: Paperclip::CommandNotFoundError>
Now it's clear to me the reason; identify is actually in /usr/bin/ not /Users/marky/bin/ which is from my dev machine. I have:
Paperclip.options[:command_path] = "/usr/bin"
in my development.rb
, but I'm still getting the error. I have no idea how to fix this, can anyone help?
Install following packages for working with imagemagick
1) apt-get install imagemagick
2) apt-get install libmagickwand-dev
3) gem install rmagick
I think you are missing the second one.
If you are hosting your application with Passenger, keep in mind that Passenger does not have the same $PATH variable as your logged in user. A good way to check whether Passenger can see the ImageMagick commands is to add this to one of your erb templates:
<%= `which convert` %>
<%= `echo $PATH` %>
and to compare the results with running the same commands in your terminal. Another possibility is ImageMagick can't find the libs it needs. In this case, you may need to export another variable to let ImageMagick know where the libs are:
# my config/environments/development.rb
Paperclip.options[:command_path] = "DYLD_LIBRARY_PATH='/Users/jch/Library/ImageMagick-6.6.3/lib' /Users/jch/Library/ImageMagick-6.6.3/bin"
Hope that helps -jerry
You can install ImageMagick on your machine. These problem generates because it will not find some methods.
To check ImageMagick is installed on your machine is simply run 'convert' command on terminal.
In my case, setting the Paperclip command path options under environment file for production server (NGINX + Passenger) didn't work.
I've set it in the paperclip.rb initializer file instead:
Paperclip.options[:command_path] = "/usr/bin/" if Rails.env.production?
Check if you have imagemagick installed by running
which convert
in your console. In my case, the result was the following:
$ which convert
/usr/bin/convert
Then I add the following line to config/environments/development.rb which tells Paperclip where to find Imagemagick
Paperclip.options[:command_path] = "/usr/local/bin/"
精彩评论