Why image upload could be failing just in production? - ruby-on-rails

I saw Why is Paperclip failing silently in production + development? and Paperclip images failing to save in production rails.
In development my form uploads images correctly.
In console I see log for ImageMagick commands:
Command :: identify -format %wx%h '/tmp/Screen Shot 2013-05-20 at 1.07.24 AM20130526-23150-hy913i.png[0]'
Command :: identify -format %m '/tmp/Screen Shot 2013-05-20 at 1.07.24 AM20130526-23150-hy913i.png[0]'
Command :: identify -format %m '/tmp/Screen Shot 2013-05-20 at 1.07.24 AM20130526-23150-hy913i.png[0]'
Command :: convert '/tmp/Screen Shot 2013-05-20 at 1.07.24 AM20130526-23150-hy913i.png[0]' -auto-orient -resize "10
.... more lines like these
In production I have:
Paperclip.options[:command_path] = "/usr/bin/"
And which convert outputs /usr/bin/convert
Update
I am using EC2.

Related

Paperclip on Windows: [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError>

I'm getting this error in development when I try to upload a file.
Command :: file -b --mime "C:/Users/Chloe/AppData/Local/Temp/dfeacdebdd52607b78a0eca093c2ed7a20170510-45680-1dipvsw.jpg"
Command :: identify -format '%wx%h,%[exif:orientation]' "C:/Users/Chloe/AppData/Local/Temp/dfeacdebdd52607b78a0eca093c2ed7a20170510-45680-ns50at.jpg[0]" 2>NUL
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I don't have identify command and it's not installed with ImageMagick (at least not anymore).
>dir "C:\Program Files\ImageMagick-7.0.5-Q16"\*.exe
Directory of C:\Program Files\ImageMagick-7.0.5-Q16
04/25/2017 06:26 AM 324,096 dcraw.exe
04/25/2017 06:24 AM 33,351,680 ffmpeg.exe
04/25/2017 06:24 AM 113,664 hp2xx.exe
04/25/2017 06:30 AM 201,728 imdisplay.exe
04/25/2017 06:30 AM 112,128 magick.exe
05/10/2017 08:53 PM 1,202,385 unins000.exe
6 File(s) 35,305,681 bytes
I installed ImageMagick from chocolatey. This question is similar, but out of date with no relevant answers.
Version: ImageMagick-7.0.5-Q16, paperclip (5.1.0)
You have to install
https://chocolatey.org/packages/imagemagick.tool
Instead. But you also have to adjust your path so ImageMagick's convert is before Window's convert
>where convert
C:\Windows\System32\convert.exe
C:\ProgramData\chocolatey\bin\convert.exe
Oh, and use refreshenv and restart your server.

Paperclip on Rails 4.0 strange warnings

I'm trying to test my controller which deal with images by paperclip. However, when I ran rspec, there are a lot of strange warnings from paperclip I guess. The warnings are look like this:
I, [2014-08-17T03:20:20.852108 #36314] INFO -- : Command :: identify -format '%wx%h,%[exif:orientation]' 'spec/assets/images/test_banner.jpg[0]' 2>/dev/null
I, [2014-08-17T03:20:20.866725 #36314] INFO -- : Command :: identify -format '%wx%h,%[exif:orientation]' 'spec/assets/images/test_banner.jpg[0]' 2>/dev/null
I, [2014-08-17T03:20:20.881726 #36314] INFO -- : Command :: identify -format '%wx%h,%[exif:orientation]' 'spec/assets/images/test_banner.jpg[0]' 2>/dev/null
Can anyone tell me what are those warnings and how can I fix it?
Environment infos: Rails 4.1.4, latest paperclip, mongoid-paperclip.
Those are not warnings, they are informational statements that paperclip is logging. You can turn paperclip's logging off for testing by adding the following in your config/environments/test.rb:
Your::Application.configure do
...
Paperclip.options[:log] = false
...
end
See Paperclip readme for further details.

Rails 3 Paperclip issues

i'm using Rails 3 and paperclip to upload some pictures.
However, each time i want to upload some pictures, if i perform a
new_picture.valid?
it returns me false.
I installed imageMagick and set the path in my windows environment variables.
But here is a problem, i'm using thin server, and in the console it return me a message when i try to upload the pictures:
I'm French, it returns me
"Paramètre non valide - /Users"
In english : "Invalid Parameter - /Users"
Here is what my image parameter contain:
"image"=>[#<ActionDispatch::Http::UploadedFile:0x5770710 #original_filename="Desert.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"service[service_pictures][image][]\"; filename=\"Desert.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:C:/Users/XXX/AppData/Local/Temp/RackMultipart20140210-2252-3r9p4g>>]
I think that the problem is located in where the tempfile is placed : "C:/Users/...
Because i'm french, on my computer C:/Users is named C:/Utilisateurs
Do you think that due to this ImageMagick would not be able to find the tempfile and so unable to perform its actions on it?
Here are my logs
Command :: identify -format '%wx%h,%[exif:orientation]' "C:/Users/Fred-Dev/AppData/Local/Temp/Desert20140210-2252-jpumkw.jpg[0]"
Command :: identify -format %m "C:/Users/Fred-Dev/AppData/Local/Temp/Desert20140210-2252-jpumkw.jpg[0]"
Command :: identify -format %m "C:/Users/Fred-Dev/AppData/Local/Temp/Desert20140210-2252-jpumkw.jpg[0]"
Command :: identify -format %m "C:/Users/Fred-Dev/AppData/Local/Temp/Desert20140210-2252-jpumkw.jpg[0]"
Command :: convert "C:/Users/Fred-Dev/AppData/Local/Temp/Desert20140210-2252-jpumkw.jpg[0]" -auto-orient -resize "x144" -crop "145x144+23+0" +repage "C:/Users/Fred-Dev/AppData/Local/Temp/Desert20140210-2252-jpumkw20140210-2252-1fia7d"
[paperclip] An error was received while processing:
Paperclip::Error: There was an error processing the thumbnail for Desert20140210-2252-jpumkw>
Have you any idea on how i could solve my problem?
Thanks in advance for the help
best regards
RESOLVED
In fact in the windows environment variables, you have to place the path to imageMagick in FIRST, before the windows one.
It's now working properly for me!

Paperclip style not respected

I have a Picture model, which has attached file picture, using Paperclip.
class Picture < ActiveRecord::Base
[...]
has_attached_file :photography, styles: { thumb: '115x', gallery: '560x560' }
[...]
end
File corresponding to thumb style is perfect but file corresponding to gallery style is always 560px width. I want to obtain a file with every sides of 560px maximum.
Eg:
Original size 1000x800px => gallery size 560x468
Original size 800x1000px => gallery size 700x560
Paperclip debug output:
Started POST "/admin/pictures/create" for 127.0.0.1 at 2013-01-29 13:21:26 +0100
Processing by Admin::PicturesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"3mDW4HeWq3SV/KJ8ez09c+/Y1dNcCkqN+8uUUx5SnGk=", "picture"=>{"realization_id"=>"3", "photography"=>#<ActionDispatch::Http::UploadedFile:0x007fe984776c10 #original_filename="IFFTS-37-2.jpeg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"picture[photography]\"; filename=\"IFFTS-37-2.jpeg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/RackMultipart20130129-12408-a9zr3v>>, "name"=>"test", "active"=>"1"}, "_save"=>"Save"}
Command :: identify -format %wx%h '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: identify -format %m '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: identify -format %m '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: convert '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]' -auto-orient -resize "115" '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja20130129-12408-1boh1t1'
Command :: file -b --mime '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja20130129-12408-1boh1t1'
Command :: identify -format %wx%h '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: identify -format %m '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: identify -format %m '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]'
Command :: convert '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja.jpeg[0]' -auto-orient -resize "560x560" '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja20130129-12408-fqtxxs'
Command :: file -b --mime '/var/folders/gh/q_r38fpj4qv5t8ymtq713d_w0000gn/T/IFFTS-37-220130129-12408-ssh5ja20130129-12408-fqtxxs'
If I run the same command in terminal, everything works fine:
convert picture.jpeg -auto-orient -resize 560x560 picture.jpeg
(Same issue on Heroku)
Any ideas ?
Try Following
has_attached_file :photography, styles: { thumb: '115x', gallery: '560x560>' }
I suggest you to stop using paperclip since its heavy and use carrierwave. Its quite light. I was using paperclip initially and then switched to carrierwave. Pretty simple to deploy.

Paperclip attachments don't save under unicorn

I'm running a rails 3.0.12 application with Paperclip 2.6 under Ubuntu + Nginx + Unicorn setup. In production, my image attachments seemed to upload fine, but upon checking the image path, I couldn't find the files, so I started messing around.
Ultimately, I found that if I ran the built-in rails dev server (rails s), the attachments would upload just fine to the correct path. But under unicorn, while the attachments do get uploaded, a) they get saved to /tmp/randompath on the server, and all the resized images for each of the styles also get saved with a bunch of random characters in the filename, including the upload date and time.
Not sure what is going on here. Here is the rails log when run under the rails dev server (in the production environment):
Command :: identify -format %wx%h '/tmp/stream20120626-4215-axmd16.png[0]'
Command :: convert '/tmp/stream20120626-4215-axmd16.png[0]' -resize "x100" -crop "100x100+185+0" +repage '/tmp/stream20120626-4215-axmd1620120626-4215-1droo3w'
Command :: identify -format %wx%h '/tmp/stream20120626-4215-axmd16.png[0]'
Command :: convert '/tmp/stream20120626-4215-axmd16.png[0]' -resize "280x" -crop "280x55+0+2" +repage '/tmp/stream20120626-4215-axmd1620120626-4215-fzxeg1'
...
...
UPDATE `organizations` SET `logo_file_name` = 'logo.png', `logo_file_size` = 5682, `logo_updated_at` = '2012-06-26 19:48:47', `updated_at` = '2012-06-26 19:48:48' WHERE `organizations`.`id` = 1
[paperclip] Saving attachments.
[paperclip] saving /home/deploy/apps/xxx_staging/releases/20120626193037/public/system/organization/1/original/logo.png
[paperclip] saving /home/deploy/apps/xxx_staging/releases/20120626193037/public/system/organization/1/thumb/logo.png
And under unicorn, the log shows:
Command :: identify -format %wx%h '/tmp/1docway_logo20120626-11230-1wodane.jpg[0]'
Command :: convert '/tmp/1docway_logo20120626-11230-1wodane.jpg[0]' -resize "x100" -crop "100x100+135+0" +repage '/tmp/1docway_logo20120626-11230-1wodane20120626-11230-1y0j5hm'
Command :: identify -format %wx%h '/tmp/1docway_logo20120626-11230-1wodane.jpg[0]'
Command :: convert '/tmp/1docway_logo20120626-11230-1wodane.jpg[0]' -resize "280x" -crop "280x55+0+10" +repage '/tmp/1docway_logo20120626-11230-1wodane20120626-11230-1bwx4go'
[paperclip] Saving attachments.
[paperclip] deleting /home/deploy/apps/xxx_staging/releases/20120620214744/public/organization/1/original/1docway_logo.png
[paperclip] deleting /home/deploy/apps/xxxx_staging/releases/20120620214744/public/organization/1/thumb/1docway_logo.png
As you can see, the second set of logs has no UPDATE command being run, or files being saved to the /home/deploy/apps/xxx_staging/releases/xxx/public/system/ folder

Resources