Unable to upload paperclip image in production (AWS) - ruby-on-rails

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.

Related

Solidus - cannot upload or view images (ImageMagick is installed)

I'm just starting with Solidus, though I do know my way around Rails. I've created a Solidus project on my Mac, and I installed all the required gems as well as ImageMagick through Homebrew. Both identify and magick work as terminal commands as my /usr/local/bin directory is in my PATH. I've also specified the path to identify in the application.rb file (I'm guessing it's supposed to go in side the Application class). However, none of the images show up in Solidus, and when I try and manually add an image, I get the following error (it's related to paperclip). Any help here would be - Google has not been my friend this time. The error message is shown below:
[paperclip] Trying to link /tmp/RackMultipart20200622-9041-8gndhx.jpg to /tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1t35lnu.jpg
[paperclip] Trying to link /tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1t35lnu.jpg to /tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-62aumc.jpg
Command :: PATH=/usr/local/bin/identify:$PATH; file -b --mime '/tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-62aumc.jpg'
Command :: PATH=/usr/local/bin/identify:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1t35lnu.jpg[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: PATH=/usr/local/bin/identify:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1t35lnu.jpg[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: PATH=/usr/local/bin/identify:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1t35lnu.jpg[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: PATH=/usr/local/bin/identify:$PATH; identify -format '%wx%h,%[exif:orientation]' '/tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1t35lnu.jpg[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
[paperclip] Trying to link /tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1t35lnu.jpg to /tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1dlkgdw.jpg
Command :: PATH=/usr/local/bin/identify:$PATH; file -b --mime '/tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1dlkgdw.jpg'
[paperclip] Trying to link /tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-1t35lnu.jpg to /tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-16yjulo.jpg
Command :: PATH=/usr/local/bin/identify:$PATH; file -b --mime '/tmp/cdcf58ad03be2998ea64da8e6cd3e43c20200622-9041-16yjulo.jpg'
Rendering /Library/Ruby/Gems/2.6.0/gems/solidus_backend-2.10.1/app/views/spree/admin/images/create.js.erb
Rendered /Library/Ruby/Gems/2.6.0/gems/solidus_backend-2.10.1/app/views/spree/admin/images/create.js.erb (Duration: 3.4ms | Allocations: 874)
Completed 200 OK in 836ms (Views: 20.7ms | ActiveRecord: 7.6ms | Allocations: 29100)

Ubuntu Rails 4 Paperclip::Errors::NotIdentifiedByImageMagickError

I've seen similar post with this error but none of them fixed my problem. I'm using ImageMagick (6.9.0.8)and Paperclip for uploading images to my Rails 4 app. It is working on my development machine, a Mac, but not on my DigitalOcean account (Ubuntu 14.04, Nginx, Unicorn). When Paperclip tries saving different sizes of the images, ImageMagick give the error:
Paperclip::Errors::NotIdentifiedByImageMagickError
I'm using the Paperclip 4.2.1 and Cocaine .0.5.5 gems. In my Rails model I have:
has_attached_file :photo_image, :styles => { :medium => "330x250#", :small => "150x120#", :thumb => "120x100#" },
:url => "/system/dadverts/:attachment/:id/:style/:filename",
:path => ":rails_root/public/system/dadverts/:attachment/:id/:style/:filename",
:default_url => "300250ad.png"
validates_attachment_content_type :photo_image, :content_type => /\Aimage/
In my production environment settings I have:
Processing by AdvertisementsController#create as HTML
I, INFO -- : Parameters: {"utf8"=>"✓", "authenticity_token"=>"8hHWBxpydUyA1MEucXtnSvvRvHc38LcM1hbb8Is/cd4=", "advertisement"=>{"customer_name"=>"Kayak Venice", "ad_network_name"=>"Recon Outpost", "sitead_location_id"=>"1", "publish_date(1i)"=>"2015", "publish_date(2i)"=>"3", "publish_date(3i)"=>"14", "expiration_date(1i)"=>"2020", "expiration_date(2i)"=>"3", "expiration_date(3i)"=>"14", "keywords_alt_text"=>"", "sort_order"=>"1", "local_ad"=>"0", "zipcode"=>"00000", "photo_image"=>#<ActionDispatch::Http::UploadedFile:0x00000005c93038 #tempfile=#<Tempfile:/tmp/RackMultipart20150314-2186-1jc6u31>, #original_filename="KayakLogoConcept3.png", #content_type="image/png", #headers="Content-Disposition: form-data; name=\"advertisement[photo_image]\"; filename=\"KayakLogoConcept3.png\"\r\nContent-Type: image/png\r\n">, "render_options"=>"1", "click_thru_url"=>"", "external_media_embed"=>""}, "advertisment"=>{"publish"=>"0"}, "commit"=>"Create Advertisement"}
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH file -b --mime '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-pxyhur.png'
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-o1r33b.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-o1r33b.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-o1r33b.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH file -b --mime '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-91e4eo.png'
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-fwjtt8.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-fwjtt8.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH identify -format '%wx%h,%[exif:orientation]' '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-fwjtt8.png[0]' 2>/dev/null
I, INFO -- : [paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
I, INFO -- : Command :: PATH=/usr/local/bin/:$PATH file -b --mime '/tmp/af961aaf697aaa71682a6e9716d6034520150314-2186-k19vf3.png'
I, INFO -- : Rendered advertisements/_form.html.erb (65.2ms)
This error class has description:
# Will be thrown when ImageMagic cannot determine the uploaded file's
# metadata, usually this would mean the file is not an image.
This is mean that you are trying to process not image file. Seems like it can be related to incorrect extension of temporary file. Look at this file extension:
af961aaf697aaa71682a6e9716d6034520150314-2186-o1r33b.png[0]
As you can see it has [0] at the end. So, try to investigate why this extension is appear. Seems like you are using custom processor base on Cocaine. I think problem can be related to it.
Anything new for this issue?
I got the same problem and open a new issue on github:
https://github.com/thoughtbot/cocaine/issues/84

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.)

Resources