Paperclip Error: NotIdentifiedByImageMagickError

2020-03-01 08:33发布

I've had a rails install with Paperclip working just fine for a while now and in a recent deploy it has broken. I believe it coincided with a gemfile update, because nothing else on the machine has changed. The error is:

Command :: file -b --mime :file
[paperclip] Error while determining content type: Command 'file -b --mime :file' returned 1. Expected 0

This is on a png file that I've verified to be valid. When I run 'file -b --mime' on the image I get:

image/png; charset=binary

I also get this afterwards:

Command :: identify -format %wx%h :file
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: /tmp/song_waveform_3010520121008-23335-165xag4.png20121008-23335-j8e18p is not recognized by the 'identify' command.>

I did a which file and it gave me /usr/bin so I tried setting the Paperclip.options[:command_path] = "/usr/bin/" in production.rb with no change.

I can't think of why this could be happening. Perhaps it's not pointing to the right directory? I'm a bit lost here.

7条回答
家丑人穷心不美
2楼-- · 2020-03-01 09:22

it used to work fine for pdf and images, tried out for an hour or so, followed everything I googled later the problem was found in my model has_attached_file :attachment,

:styles => {:original=> "125x125#"}

had to comment this line, and it worked for other attachments like docx or odt etc..

查看更多
▲ chillily
3楼-- · 2020-03-01 09:27

I ran into this after upgrading to Mavericks. I ended up solving the problem by unlinking jpeg and re-linking it

brew unlink jpeg
brew link jpeg

And everything worked fine. BTW, running Paperclip 4.1

查看更多
何必那么认真
4楼-- · 2020-03-01 09:32

I had this issue when using OSX + MAMP + Passenger + Paperclip and after setting the command_path and ensuring imagemagick was properly installed via brew, properly setting the temp and upload directories for passenger to something writable, it still wouldn't work!

The solution was to edit the envvars file for MAMP in /Applications/MAMP/Library/bin/envvars and comment out the export DYLD_LIBRARY_PATH line.

That is, change the line that says

export DYLD_LIBRARY_PATH

to

# export DYLD_LIBRARY_PATH

Then restart MAMP and feel the elation when your images are properly uploading/resizing.

查看更多
smile是对你的礼貌
5楼-- · 2020-03-01 09:35

After all your changes, don't forget to restart your server...!

查看更多
我命由我不由天
6楼-- · 2020-03-01 09:36

Most likely this is caused by the API change in Cocaine 4 which Paperclip has not caught up to yet. Try using the earlier version of Cocaine by inserting this line into your Gemfile:

gem "cocaine", "= 0.3.2" 
查看更多
疯言疯语
7楼-- · 2020-03-01 09:38

For those who have a similar problem, be sure to double check that ImageMagick is installed, or make sure you do not use the 'styles' option.

查看更多
登录 后发表回答