Rails 3 Paperclip issues - ruby-on-rails

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!

Related

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.

Why image upload could be failing just in production?

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.

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.

ERROR Errno::EINVAL: Invalid argument - <STDOUT> while uploading image with paperclip

I'm using Paperclip with ActiveAdmin to upload pictures in Articles.
But I have a problem, when I'm editing an existing article, the first time after Webrcik started, it functions very well. But systematically, the second time I try to edit an article (whatever the one) Windows tells me that "file.exe" stopped to function, and " Internal Server Error Invalid argument - STDOUT " appears in the browser.
So, I restart webrick, and upload works only one time etc...
Here's the log :
Started PUT "/admin/articles/1" for 127.0.0.1 at 2012-10-24 18:11:45 +0200
Processing by Admin::ArticlesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"VaB3lx3UZaOjUA6Yh+h8jG7ZExSQZDiyZUw6GYJQPbY=", "article"=>{"title"=>"ee", "desc"=>"ee", "content"=>"eeee", "photo"=>#<ActionDispatch::Http::UploadedFile:0x3cce7f0 #original_filename="Desert.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"article[photo]\"; filename=\"Desert.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:C:/Users/Greg/AppData/Local/Temp/RackMultipart20121024-6620-oorxwu>>}, "commit"=>"Update Article", "id"=>"1"}
[1m[35mAdminUser Load (0.0ms)[0m SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 2 LIMIT 1
[1m[36mArticle Load (1.0ms)[0m [1mSELECT `articles`.* FROM `articles` WHERE `articles`.`id` = ? LIMIT 1[0m [["id", "1"]]
Command :: identify -format %wx%h "C:/Users/Greg/AppData/Local/Temp/Desert20121024-6620-16n1ehl.jpg[0]"
Command :: identify -format %m "C:/Users/Greg/AppData/Local/Temp/Desert20121024-6620-16n1ehl.jpg[0]"
Command :: identify -format %m "C:/Users/Greg/AppData/Local/Temp/Desert20121024-6620-16n1ehl.jpg[0]"
Command :: convert "C:/Users/Greg/AppData/Local/Temp/Desert20121024-6620-16n1ehl.jpg[0]" -auto-orient -resize "510x" -crop "510x350+0+16" +repage "C:/Users/Greg/AppData/Local/Temp/Desert20121024-6620-16n1ehl20121024-6620-mvfl3a"
Command :: file -b --mime "C:/Users/Greg/AppData/Local/Temp/Desert20121024-6620-16n1ehl20121024-6620-mvfl3a"
[paperclip] Error while determining content type: Command 'file -b --mime :file' returned 255. Expected 0
Command :: identify -format %wx%h "C:/Users/Greg/AppData/Local/Temp/Desert20121024-6620-16n1ehl.jpg[0]"
Command :: identify -format %m "C:/Users/Greg/AppData/Local/Temp/Desert20121024-6620-16n1ehl.jpg[0]"
Completed 500 Internal Server Error in 22073ms
Errno::EINVAL (Invalid argument - ruby_setenv):
I've been searching for a solution...but I did not find one.
Does someone have an idea of the source of the problem ?
The 'file' program isn't a part of Windows, which suggests you installed it (or something that includes it) to get this far - any idea what that was? Gnu provides a Windows version of 'file' as part of GnuWin32.
Learning more about your copy of that program will probably be the first step to fixing your problem. (Hope this helps.)

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