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
Related
I'm having this issue with uploading paperclip documents with rails fixture_file_upload (after upgrading rails version)
Knowing that paperclip 4.0 and above requires validating content_type, My specs still fails with the error: File has an extension that does not match its contents even after either after the validation or specifically requesting do_not_validate_attachment_file_type.
I'm having this scenario in multiple(all my) paperclip models...
An example is as follow:
Model:
class SignatureFile < ActiveRecord::Base
...
has_attached_file :file
VALID_CONTENT_TYPES = ["image/jpeg", "image/jpg", "image/png", "image/gif"]
validates_attachment :file, content_type: { content_type: VALID_CONTENT_TYPES },
convert_options: { all: '-auto-orient' },
processors: [:compression]
...
end
Spec:
image = fixture_file_upload('spec/fixtures/mobile_api/sample.jpg', 'image/jpg')
When I try to save image above, it fails, and image.errors.full_messages gives:
"File has an extension that does not match its contents"
Suffice to say I have a bunch of scenarios like this one which was previously passing before the upgrade.
Below are versions of the related gems I have:
gem 'rails', '4.2.7.1'
gem 'paperclip', '4.2.1'
gem 'paperclip-compression', '0.3.7'
gem 'rspec-rails', '3.4.2'
What can I be missing here?
You might be missing file, sadly the error isn't more precise in those cases. Read in the paperclip docs.
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
Ruby newbie here, using Rails 1.9.3 and Ruby 4.0. I am trying to use Paperclip from http://railscasts.com/episodes/134-paperclip, when running command: rails plugin install git://github.com/thoughtbot/paperclip.git
I get the following error C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesupport-4.0.0/lib/active_support/dependencies.rb:228:in 'require': cannot load such file -- rails/commands/plugin (LoadError)
Has anyone come across this problem or suggest a solution, thanks all.
documentations for paperclip gem has all the information needed:
https://github.com/thoughtbot/paperclip
the railscast that you use is 5 years old, and starting with rails 3 all plugins can be installed as gems in Gemfile or systemwide with gem install your_gem.
Gemfile
gem "paperclip", :git => "git://github.com/thoughtbot/paperclip.git"
model
attr_accessible :avatar
has_attached_file :avatar, :styles => { :medium => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"
continue with docs https://github.com/thoughtbot/paperclip
Joshua, plugins have been disabled in Rails 4. The proper way is to add the paperclip gem to your Gemfile and do bundle install
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.
Image Uploading was working fine, but when I tried switching it to S3, it started throwing an error. I get the following error when I try to create a new image upload:
cannot load such file -- aws-sdk (You may need to install the aws-sdk gem)
Relevant gems:
gem 'rails', '3.2.5'
gem 'paperclip'
gem 'aws-sdk'
config/s3.yml:
development:
bucket: bucketname
access_key_id: #
secret_access_key: #
test:
bucket: bucketname
access_key_id: #
secret_access_key: #
image_upload.rb:
has_attached_file :image,
:styles => {
:normal => "1680x6000",
:result => "560x3000",
:thumb => "140x500" },
:path => ":attachment/:style/:normalized_file_name.:extension",
:storage => :s3,
:s3_credentials => "#{Rails.root}/config/s3.yml"
Things I have tried:
bundle install
Change the version of aws-sdk to 1.3.4
gem install aws-sdk
Changed the s3_credentials "Rails.root" part to a few different things.
Thank you for the help!!
A little embarrassing... I just needed to restart rails server. Can't believe I forgot to do that.
What happens if you add require 'rubygems' to the top of the file where you are requiring aws-sdk?