Paperclip, s3 fail to upload but didn't show any errors - ruby-on-rails

I've been searching for solutions in similar topics of this but I can't get it to work somehow.
This is my application log
Command :: identify -format %wx%h '/tmp/0120121215-31657-19vihny.jpg[0]'
Command :: convert '/tmp/0120121215-31657-19vihny.jpg[0]' -auto-orient -resize "32x32!" - background white -flatten +matte '/tmp/0120121215-31657-19vihny20121215-31657-58mm3a.png'
Command :: identify -format %wx%h '/tmp/0120121215-31657-19vihny.jpg[0]'
Command :: convert '/tmp/0120121215-31657-19vihny.jpg[0]' -auto-orient -resize "320x320!" -background white -flatten +matte '/tmp/0120121215-31657-19vihny20121215-31657-1n3fgl2.png'
[paperclip] Saving attachments.
[paperclip] saving images/:User/50cc0cfb0feea807f6000004/original.jpg
[paperclip] saving images/:User/50cc0cfb0feea807f6000004/small.png
[paperclip] saving images/:User/50cc0cfb0feea807f6000004/medium.png
Started POST "/photos" for 127.0.0.1 at 2012-12-15 12:39:07 +0700
Processing by PhotosController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"SSjceuOzRNQfJyUCki86mNBfuHsK0bh5qQmX4pBi7uk=", "photo"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0xb27e0164 #original_filename="01.jpg", #content_type="image/jpeg", #headers="Content-Disposition: form-data; name=\"photo[image]\"; filename=\"01.jpg\"\r\nContent-Type: image/jpeg\r\n", #tempfile=#<File:/tmp/RackMultipart20121215-31657-9oqjbm>>, "description"=>"This is decscription"}, "commit"=>"Create Photo"}
MOPED: 127.0.0.1:27017 COMMAND database=admin command={:ismaster=>1} (0.7489ms)
MOPED: 127.0.0.1:27017 INSERT database=image12345_development collection=photos documents=[{"_id"=>"50cc0cfb0feea807f6000004", "image_file_name"=>"01.jpg", "image_content_type"=>"image/jpeg", "image_file_size"=>368812, "image_updated_at"=>2012-12-15 05:39:07 UTC, "description"=>"This is decscription"}] flags=[] (0.2658ms)
[AWS S3 200 8.971826 0 retries] put_object(:acl=>:public_read,:bucket_name=>"image12345",:content_length=>368812,:content_type=>"image/jpeg",:data=>Paperclip::UploadedFileAdapter: 01.jpg,:key=>"images/:User/50cc0cfb0feea807f6000004/original.jpg")
[AWS S3 200 0.214209 0 retries] put_object(:acl=>:public_read,:bucket_name=>"image12345",:content_length=>2763,:content_type=>"image/png",:data=>Paperclip::FileAdapter: 0120121215-31657-19vihny20121215-31657-58mm3a.png,:key=>"images/:User/50cc0cfb0feea807f6000004/small.png")
[AWS S3 200 3.498196 0 retries] put_object(:acl=>:public_read,:bucket_name=>"image12345",:content_length=>142791,:content_type=>"image/png",:data=>Paperclip::FileAdapter: 0120121215-31657-19vihny20121215-31657-1n3fgl2.png,:key=>"images/:User/50cc0cfb0feea807f6000004/medium.png")
Redirected to http://localhost:3000/photos/50cc0cfb0feea807f6000004
Completed 302 Found in 12992ms
I use devise for user
In my gem file There's
gem "mongoid-paperclip", :require => "mongoid_paperclip"
gem 'paperclip'
gem "aws-sdk"
In my models/photo.rb
has_mongoid_attached_file :image,
:path => ':attachment/:User/:id/:style.:extension',
:storage => :s3,
:s3_credentials => File.join(Rails.root, 'config', 's3.yml'), #s3.yml contain credentials
:styles => {
:small => ['32x32!', :png],
:medium => ['320x320!', :png, :jpg],
},
:convert_options => { :all => '-background white -flatten +matte' }
attr_accessible :image, :description
in my form
<%= form_for(#photo , :html => {:multipart => true} ) do |f| %>
<div class="field">
<%= f.label :image %><br />
<%= f.file_field :image %>
</div>
<% end %>
I've already tried many solutions like add form_helper :multipart and in my previous applications, this model and gem worked finely and I'm sure that the credential is correct. it's just told me that it's a success update but no image is uploaded.
Where can I look for an errors on this issue? or any tools I can use ? I'm really stuck on this and want to get through it, not creating new app and wish for luck.

Already found the solution sometime ago but forget to post
it's the same problem at this question
Rails 3 - Amazon S3 Paperclip EU Problem
figured it out when I see a picture has already been uploaded but it's just I didn't use the right address to access them :)

Related

Paperclip for both images and Videos

In my app I already have paperclip for upload images, but requirement changed in order to accept both images and videos. The images are already defined in a model with a belongs_to relationship, called Attachment. Since the video will also be an attachment of the same parent model (in my case, articles) I wanted to reuse the same Attachment model for images & videos. Is this a good idea?
The code of my attachment.rb is:
class Attachment < ActiveRecord::Base
belongs_to :article
has_attached_file :url, :s3_protocol => :https ,
styles: {
medium: "300x300>", thumb: "100x100>", big: "1200x1200>", normal: "600x600>"
}
validates_attachment_content_type :url, content_type: /\Aimage|\Avideo\/.*\Z/
validates_attachment :url, content_type: { content_type: ["image/jpeg", "image/gif", "image/png", "video/mp4"] }
end
But as it is, it's not storing videos on the S3. I get the following in the terminal
Command :: file -b --mime '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/f3e2afc957bb9fb2aa3e77e69359c48920160131-13311-pyeez1.mp4'
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/8dc7385648e2164764b72fda6fd9099a20160131-13311-1l40ccn.mp4[0]' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::Errors::NotIdentifiedByImageMagickError: Paperclip::Errors::NotIdentifiedByImageMagickError>
Command :: file -b --mime '/var/folders/v_/pf2bsxnj1y37ccd2pjksv7z80000gn/T/f3e2afc957bb9fb2aa3e77e69359c48920160131-13311-kvb5nr.mp4'
The second question is since I'm using AngularJS for the frontend, can I just take advantage of HTML <video> tag to render the video to the user?
Looks like the issue is that ImageMagick is trying to transcode the video, which it cannot.
The way to handle transcoding of videos within Paperclip is to use the paperclip-av-transcoder gem (formerly paperclip-ffmpeg). I only have experience with the latter:
#app/models/attachment.rb
class Attachment < ActiveRecord::Base
has_attached_file :url, :s3_protocol => :https ,
styles: lambda { |a| a.instance.is_image? ? medium: "300x300>", thumb: "100x100>", big: "1200x1200>", normal: "600x600>" } : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}}, processors: [:transcoder]
validates_attachment :url,
content_type: ['video/mp4'],
message: "Sorry, right now we only support MP4 video",
if: :is_video?
validates_attachment :url,
content_type: ['image/png', 'image/jpeg', 'image/jpg', 'image/gif'],
message: "Different error message",
if: :is_image?
private
def is_video?
url.instance.attachment_content_type =~ %r(video)
end
def is_image?
url.instance.attachment_content_type =~ %r(image)
end
end
Our old code & ref

Paperclip - No route matches GET

Paperclip 2.7
Ruby 1.8.7 Enterprise
Rails 3.1.0
Imagemagick 6.6
When i upload an image im my app, they are correctly processed by imagemagick and they are stored in conrrectly path. But, when i need to take this file to show, is not found.
Saving image:
Started POST "/p" for 177.16.57.105 at Sun Sep 23 23:39:16 -0300 2012
Processing by ProductsController#create as HTML
Parameters: {"commit"=>"Salvar", "authenticity_token"=>"EgBUGfKIIduS2lkl0mh5p27pT0vF0/P8HXO852KHMM8=", "utf8"=>"â", "product"=>{"photo"=>#>, "price"=>"", "name"=>"Brigadeiro de pistache", "product_type"=>"1", "featured"=>"0", "description"=>"Brigadeiro de pistache"}}
[32mCommand[0m :: convert '/tmp/stream20120923-19588-vw8u1s-020120923-19588-3lym39-0[0]' -resize "120x80>" '/tmp/stream20120923-19588-vw8u1s-020120923-19588-3lym39-020120923-19588-16ky3i8-0'
[paperclip] Saving attachments.
[paperclip] saving /home/brigaderiagourmand/apps_rails/site/public/system/photos/24/short/brigadeirocolorido.png
Redirected to http://brigaderiagourmand.com.br/p/24
Completed 302 Found in 257ms
And when i need take the file...
Started GET "/photos/original/missing.png" for 177.16.57.105 at Sun Sep 23 23:39:17 -0300 2012
ActionController::RoutingError (No route matches [GET] "/photos/original/missing.png"):
My model
class Product < ActiveRecord::Base
attr_accessible :name, :description, :price, :photo, :product_type, :featured
attr_accessor :photo_file_name
has_attached_file :photo, :styles => { :thumb => "50x50>", :medium => "280x180>", :large => "585x400>", :short => "120x80>", :original => "200,200>" }
TYPES = ["Belga", "Normal"]
end
Form views
= form_for #product, :html => {:multipart => true} do |f|
= f.file_field :photo
Show view
= image_tag #product.photo.url(:original)
Is the output from processing the image complete?
In your output paperclip only re-sizes to short (120x80>)
Your get request is trying to load the missing.jpg which is a default for image if the the requested couldn't be found. Take a look into /home/brigaderiagourmand/apps_rails/site/public/system/photos/24/ and see if there are the other re-sized photos.
There is a great screencast from Ryan Bates about paperclip
Hope this helps you

paperclip not displaying medium or thumb in rails 3.1

I'm using paperclip with Rails 3.1. When I add the image, it shows me the original size but doesn't show me thumb or medium sizes:
Here is what I have in my view:
<%= image_tag #image.avatar.url(:thumb) %>
<%= image_tag #image.avatar.url(:medium) %>
image.rb
has_attached_file :avatar, :whiny => false, :styles => { :medium => "300x300>", :thumb => "100x100>" }
UPDATE:
Here is the error I'm getting with :whiny => true
Command :: identify -format %wx%h '/var/folders/54/txjcl9l130j6dq73r37hf2c00000gn/T/stream20111213-9180-1plu1me.png[0]'
[paperclip] An error was received while processing: #
Command :: identify -format %wx%h '/var/folders/54/txjcl9l130j6dq73r37hf2c00000gn/T/stream20111213-9180-1plu1me.png[0]'
[paperclip] An error was received while processing: #
Rendered images/new.html.erb within layouts/application (4.0ms)
First, make sure that Image Magick is installed.
To see if its installed properly, go to a terminal session and type which convert. You should see a path to the executable.
Once that is done, you may need to add the path to your environment.rb file. For example, my convert is located at /usr/local/bin/convert. Now I've seen two different ways of setting your path for paperclip, try one or the other and see what works.
# specifically set the paperclip path
Paperclip.options[:command_path] = '/usr/local/bin'
# set the path in general, might not be necessary
ENV['PATH'] = '/usr/local/bin:' + ENV['PATH']

rails + paperclip + plupload

Hi i'm using paperclip and plupload like in this tutorial:
http://www.theroamingcoder.com/node/50
It works.
But if i try to set thumbnails with paperclip like:
has_attached_file :data,
:styles => { :medium => "558x418>", :thumb => "60x82>" }
It doesn't work.
I receive this error:
[paperclip] identify -format %wx%h '/tmp/stream20110209-26212-1l2obtp-0.png[0]' 2>/dev/null
[paperclip] convert '/tmp/stream20110209-26212-1l2obtp-0.png[0]' -resize "558x418>" '/tmp/stream20110209-26212-1l2obtp-020110209-26212-cl5lbg-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110209-26212-1l2obtp-0>
[paperclip] identify -format %wx%h '/tmp/stream20110209-26212-1l2obtp-0.png[0]' 2>/dev/null
[paperclip] convert '/tmp/stream20110209-26212-1l2obtp-0.png[0]' -resize "60x82>" '/tmp/stream20110209-26212-1l2obtp-020110209-26212-1m6qvkj-0' 2>/dev/null
[paperclip] An error was received while processing: #<Paperclip::PaperclipError: There was an error processing the thumbnail for stream20110209-26212-1l2obtp-0
How can i solve it?
thanks
It looks like you don't have Imagemagick installed!
http://www.imagemagick.org/script/index.php
If I am wrong try this
has_attached_file :data, :styles => { :medium => ["558x418>", :png], :thumb => ["60x82>", :png] }
I had to disable chunks in plupload

rails routes using picnik with paperclip

I've been trying to get picnik to work with paperclip so I can resize and touch up images, however have had some difficulty so far.
I'm a bit confused over the routing, as I get an error:
Started POST "/products/3/photos/4" for 208.88.21.57 at Fri Dec 10 14:44:59 -0800 2010
ActionController::RoutingError (No route matches "/products/3/photos/4"):
This is when I try to pass the file back from picnik, however simply updating the image title on the same record using the exact same path seems to work fine and uses the exact same routing as above:
Started POST "/products/3/photos/4" for 69.149.172.21 at Fri Dec 10 14:52:29 -0800 2010
Processing by PhotosController#update as HTML
Parameters: {"photo"=>{"title"=>"Front"}, "commit"=>"Update Photo", "product_id"=>"3", "authenticity_token"=>"uZ3dV3BCSm7GvP39U51KCClx2P8gIWktyki/3rnpOIM=", "utf8"=>"\342\234\223", "id"=>"4"}
[paperclip] Saving attachments.
Redirected to http://leatherarts.heroku.com/products/3
Completed 302 Found in 17ms
What am I missing?
I ignored the authenticity token in the controller for the update action... btw
Picnik takes a basic params to submit back to by post, my line looks like this:
<%= link_to "Edit or Crop", "http://www.picnik.com/service/?_import=img&img=#{#photo.data.url(:original)}&_export=#{url_for(product_photo_url(#product,#photo))}&_export_field=photos_attributes&_export_title=SaveIt&_apikey=617c5c06600b6c21ebf0bc91eafbbae5" %>
Photo Model
has_attached_file :data,
:storage => 's3',
:s3_credentials => "#{RAILS_ROOT}/config/s3_credentials.yml",
:bucket => 'leatherarts.com',
:s3_host_alias => 'leatherarts.com.s3.amazonaws.com',
:url => ':s3_alias_url',
:path => "images/products/:product_id/:style/:basename.:extension",
:styles => { :thumb => "60x60#", :small => "200x200>", :medium => "400x400>", :large => "1000x1000>" },
:default_style => :original,
:default_url => 'http://leatherarts.com.s3.amazonaws.com/images/records/m1.png',
:s3_headers => { 'Expires' => 2.months.from_now.httpdate }
validates_attachment_presence :data
validates_attachment_size :data, :less_than => 10.megabytes
validates_attachment_content_type :data, :content_type => ['image/jpeg','image/gif','image/png']
UPDATE:
I got past the first problem with a specified PUT in a new route:
match 'products/:product_id/photos/:id/picnik' => 'photos#picnik', :as => :picnik
but still can't quite get it to all fall together. It seems to work and save, but it never saves the updated image.
I added this action in my photo controller
def picnik
#product = Product.find(params[:product_id])
#photo = Photo.find(params[:id])
#photo.data(params[:data])
if #photo.save
flash[:notice] = "Successfully updated photo."
redirect_to product_path(#product)
else
render :action => 'edit'
end
end
And according to the log it seems to do what it should:
Started POST "/products/10/photos/25/picnik" for 208.88.21.59 at Sat Dec 11 08:09:32 -0800 2010
Processing by PhotosController#picnik as HTML
Parameters: {"data"=>#<File:/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/RackMultipart20101211-7501-1tdkwuq-0>, "product_id"=>"10", "id"=>"25"}
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "x60" -crop "60x60+15+0" +repage '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-42lphg-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "1000x1000>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-1nskgrl-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "400x400>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-fpe5rc-0' 2>/dev/null
[paperclip] identify -format %wx%h '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' 2>/dev/null
[paperclip] convert '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-0[0]' -resize "200x200>" '/home/slugs/372051_88c7fa8_e87f-144ddfc3-a58b-4233-939c-2131aa001145/mnt/tmp/paperclip-reprocess20101211-7501-1fo13g4-020101211-7501-v5e99x-0' 2>/dev/null
[paperclip] saving images/products/10/original/DSC_0212.JPG
[paperclip] saving images/products/10/etsy/DSC_0212.JPG
[paperclip] saving images/products/10/thumb/DSC_0212.JPG
[paperclip] saving images/products/10/medium/DSC_0212.JPG
[paperclip] saving images/products/10/small/DSC_0212.JPG
[paperclip] Saving attachments.
Redirected to http://leatherarts.heroku.com/products/10
Completed 302 Found in 1632ms
But it's always the same image as before, with no new adjustments from picnik? I thought maybe it was the S3 Caching, but I created a new size category and it created it with the old image just the same.

Resources