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.
Related
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!
I seem to have an issue with my paperclip uploads in production. I have deployed with Capistrano to AWS. Here is the error I receive when attempting to upload an image for a user.
Started GET "/" for 127.0.0.1 at 2013-10-02 19:40:48 +0000
Processing by PagesController#home as */*
Rendered pages/home.html.erb within layouts/application (1.1ms)
Completed 200 OK in 6ms (Views: 6.0ms | ActiveRecord: 0.0ms | Solr: 0.0ms)
Started PUT "/users/19" for 98.198.30.70 at 2013-10-02 19:41:09 +0000
Processing by UsersController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"0cCRXGjztCv0vs3sxdEcv98aEKTzGcNOXumh6hYPVMU=", "user"=>{"username"=>"chicken", "email"=>"cc#cc.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "avatar"=>#<ActionDispatch::Http::UploadedFile:0x00000006f95f00 #original_filename="download.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"user[avatar]\"; filename=\"download.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/tmp/RackMultipart20131002-766-swwl63>>}, "commit"=>"Update Profile", "id"=>"19"}
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: convert '/tmp/download20131002-766-1bap7m5.jpg[0]' -auto-orient -resize "150x150>" '/tmp/download20131002-766-1bap7m520131002-766-12kdsu8'
Command :: file -b --mime '/tmp/download20131002-766-1bap7m520131002-766-12kdsu8'
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: convert '/tmp/download20131002-766-1bap7m5.jpg[0]' -auto-orient -resize "300x300>" '/tmp/download20131002-766-1bap7m520131002-766-d8rgc4'
Command :: file -b --mime '/tmp/download20131002-766-1bap7m520131002-766-d8rgc4'
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: convert '/tmp/download20131002-766-1bap7m5.jpg[0]' -auto-orient -resize "100x100>" '/tmp/download20131002-766-1bap7m520131002-766-138s58z'
Command :: file -b --mime '/tmp/download20131002-766-1bap7m520131002-766-138s58z'
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: identify -format %m '/tmp/download20131002-766-1bap7m5.jpg[0]'
Command :: convert '/tmp/download20131002-766-1bap7m5.jpg[0]' -auto-orient -resize "50x50>" '/tmp/download20131002-766-1bap7m520131002-766-wyvzz0'
Command :: file -b --mime '/tmp/download20131002-766-1bap7m520131002-766-wyvzz0'
Completed 500 Internal Server Error in 3695ms
Errno::EEXIST (File exists - /home/app/xxx.com/current/public/system):
app/controllers/users_controller.rb:94:in `update'
This is the image link generated by the view:
<img alt="10-m" src="/system/styles/dimages/000/000/519/original/10-m.jpg?1379454321">
However, when I try to browse to this directory in my app I cannot. Perhaps it's a permissions problem? The folder name for system appears in red
app#mothership:~/xxx.com/current/public$ ls
403.html 404.html 422.html 500.html assets favicon.ico robots.txt system
app#mothership:~/xxx.com/current/public$ cd system
-bash: cd: system: No such file or directory
Paperclip is trying to create the /home/app/xxx.com/current/public/system directory, but it's already there. This is likely due to an invalid symlink in your Capistrano deployment.
Check the file and take a look using ls -l and see if it's a symlink pointing the right location. If not, update the symlink by creating the target or changing the location.
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.
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
my app integrates with FB. When the user has no image, FB returns:
https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/yp/r/yDnr5YfbJCH.gif
While that looks like a normal gif, it breaks paperclip:
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "x50" -crop "50x50+14+0" +repage '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1r9c5af-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "300x300>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1cjw8np-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "100x100>" '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-1n3nk3x-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
[paperclip] identify -format %wx%h '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' 2>/dev/null
[paperclip] convert '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-0.gif[0]' -resize "x25" -crop "25x25+7+0" +repage '/var/folders/lF/lF0Ne5vGFj44kV54W3zBdU+++TI/-Tmp-/stream20110517-560-1y0qj3p-020110517-560-rhm4uk-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110517-560-1y0qj3p-0>
Even with the error, paperclip still saves the image to the model.
Questions:
Why is it breaking?
How can I tell paperclip that if there is a processing error, abort the image, not the entire process as I'm also saving names etc, but at least stop the image from saving a dead file that ends up 404ing.
Thanks
It looks like it is actually a corrupt image. Downloading it and running identify -format %wx%h yDnr5YfbJCH.gif throws the error:
identify: corrupt image `yDnr5YfbJCH.gif' # error/gif.c/PingGIFImage/958.
200x126
So you can blame Facebook for that one.
Rob on Rails has a good example on how to validate that an upload is a valid image. That should make things work nicely for your end users.