Paperclip with sidekiq - ruby-on-rails

I am using paperclip for uploading files. Does anybody have use it with sidekiq for background jobs?
I was trying to achieve something similar to railscast 383 (uploading to Amazon S3) but with paperclip and sidekiq.
I didn't find too much information for using it with sidekiq and I am thinking if I should change to carrierwave or if there is any example for paperclip and sidekiq (not with FancyUploader and delayed_jobs).

I think what you're looking for is the delayed_paperclip gem:
https://github.com/jrgifford/delayed_paperclip/
According to the gem it has a nice ActiveRecord api so you can do something like:
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
process_in_background :avatar
end

Related

Trimming and Compression the image of paperclip using rake task

I want to trimming the image of paperclip in my database.
Because I`m running my own private web service, but I forgot to add the styles when user create the image...
has_attached_file :avatar,
:storage => :s3,
:styles => { # I forgot to add this styles
:medium => "370x370#", # I forgot to add this styles
:thumbs => "120x120#" # I forgot to add this styles
}
So I want to run the rake task and trimming like 370×370# and 120×120#.
But I cant`t find the way to trimming the image after user save.
Does anyone assist me ?
The paperclip gem comes with a rake task for exactly this purpose:
rake paperclip:refresh:thumbnails
Just run that from the command line and it will take care of generating all of your reduced-size images.

Can't upload zip files using ruby on rails and paperclip gem

I'm working on a rails web application. Just created and prepared some models and stuff. The application is very simple. But now I have a problem by setting up the gem paperclip to add attachments to a model. Almost everything works fine, like attaching images/jpg or even pdf.
But I can't upload zip files. I tried different zip files, but I'm always getting:
"Attachment Paperclip::Errors::NotIdentifiedByImageMagickError"
This is my model:
class Order < ActiveRecord::Base
has_attached_file :attachment, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
validates_attachment_content_type :attachment, :content_type => ["application/pdf", "application/zip", "application/x-zip", "application/x-zip-compressed","application/octet-stream","image/jpg","image/png"]
belongs_to :client
has_one :status
end
I'm developing on a Mac (Yosemite), installed imagemagick via brew and using SQLite.
I added this to my Gemfile:
gem "paperclip", "~> 4.2"
gem 'cocaine', '~> 0.5.4'
I did research on google the last hours, and there are many people struggling with paperclip, but I didn't find anybody with problems uploading zip files.
Maybe someone can help here.
Thanks
ImageMagick can't read .zip files. See the acceptable file types here:
http://www.imagemagick.org/script/formats.php
If you're trying to generate a thumbnail from a zip file ImageMagick should fail every time.
Try adding this to your model:
before_post_process :skip_for_zip
def skip_for_zip
! %w(application/zip application/x-zip).include?(asset_content_type)
end
Then your app won't try to process zip files as images

Image file is not recognized by the 'identify' command. (heroku)

I'm trying to have Paperclip working with Heroku and Amazon S3.
Everything works fine on localhost (mac OS and Amazon), but when I'm deploying to heroku and trying the feature, I have this error :
2 errors prohibited this area from being saved:
Asset /tmp/paris20121005-2-2cwxgx.jpg is not recognized by the 'identify' command.
Asset /tmp/paris20121005-2-2cwxgx.jpg is not recognized by the 'identify' command.
It works when I remove the :styles => { } option in my model, but the file isn't processed (I need different image sizes).
I also have the rmagick gem in my gemfile.
Here is my gemfile (only the paperclip part) :
gem "paperclip"
gem "rmagick", :require => 'RMagick'
gem 'aws-sdk', '~> 1.3.4'
I don't have Paperclip.options[:command_path] set in my environment.rb or production.rb so no problem on this side.
Here is my model :
class Area < ActiveRecord::Base
require 'RMagick'
has_attached_file :asset, :styles => { :medium => "300x300>", :thumb => "180x190>" },
:storage => :s3,
:s3_credentials => "#{::Rails.root.to_s}/config/s3.yml",
:url => :s3_domain_url.to_s,
:path => "/:style/:id/:filename"
end
Any clue on that ? I've crawled every topics about it and nothing seems to work...
Thanks
Apparently the new update to Cocaine gem (0.4.0) breaks the file names for Paperclip and ImageMagick. try rolling back to the previous version (0.3.2), it worked for me.
See here:
https://github.com/thoughtbot/paperclip/issues/1038
PS I believe RMagick is no longer needed on Heroku, works fine for me without it

Paperclip is throwing a strange error all of a sudden after update

I can no longer render pages with paperclip urls in my Rails application. I recently updated my gem bundle. I'm using Rails 3.2.8 and Paperclip 3.1.4. I was using Paperclip 2.7.0 before.
The link in my view that is failing is:
ad.image.url(:medium)
My Ad model has these declarations:
Paperclip.interpolates :ad_subdomain do |attachment, style|
attachment.instance.brand.subdomain
end
has_attached_file :image,
:default_url => '/images/blank.gif',
:styles => { :medium => ["290x230>","jpg"],
:thumb => ["100x100>","jpg"] },
:storage => :file,
:path => "/mcp/ads/:style/:ad_subdomain/:basename.:extension"
The error that is being thrown is:
TypeError: wrong argument type Class (expected Module)
from /Users/me/.rvm/gems/ruby-1.9.3-p0#mcp5/gems/paperclip-3.1.4/lib/paperclip/attachment.rb:368:in `extend'
from /Users/me/.rvm/gems/ruby-1.9.3-p0#mcp5/gems/paperclip-3.1.4/lib/paperclip/attachment.rb:368:in `initialize_storage'
from /Users/me/.rvm/gems/ruby-1.9.3-p0#mcp5/gems/paperclip-3.1.4/lib/paperclip/attachment.rb:80:in `initialize'
from /Users/me/.rvm/gems/ruby-1.9.3-p0#mcp5/gems/paperclip-3.1.4/lib/paperclip/instance_methods.rb:5:in `new'
from /Users/me/.rvm/gems/ruby-1.9.3-p0#mcp5/gems/paperclip-3.1.4/lib/paperclip/instance_methods.rb:5:in `attachment_for'
from /Users/me/.rvm/gems/ruby-1.9.3-p0#mcp5/gems/paperclip-3.1.4/lib/paperclip.rb:191:in `block in has_attached_file'
For some reason, I had:
:storage => :file
in my declaration. That does not work. If you want to use the filesystem, you just leave out the storage line altogether and it will default.
Check out the requirements listed on the Paperclip github page:
Paperclip now requires Ruby version >= 1.9.2 and Rails version >= 3.0
(Only if you're going to use Paperclip with Ruby on Rails.)
If you're still on Ruby 1.8.7 or Ruby on Rails 2.3.x, you can still
use Paperclip 2.7.x with your project. Also, everything in this README
might not apply to your version of Paperclip, and you should read the
README for version 2.7 instead.

The perfect way to upload file in Rails 3.1

I'm new in Ruby/Rails, so, my question: what is the perfect way to upload file and save filename in database with rails? Are there any Gem? Or maybe there are good build-in feature?
Also try carrierwave, Ryan has a good screencast about this gem
Just take a look on the links to choose between paperClip & carrierwave :
Rails 3 paperclip vs carrierwave vs dragonfly vs attachment_fu
And
http://bcjordan.github.com/posts/rails-image-uploading-framework-comparison/
You can try Paperclip.It is most popular gem in rails community...
https://github.com/thoughtbot/paperclip
these lines do the all stuff
class User < ActiveRecord::Base
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
Try it......
Most people use the Paperclip Gem.

Resources