Validation failed: Upload file has an extension that does not match its contents

The Paperclip spoofing validation checks are failing because the file command is not able to accurately determine the filetype. In your log content type discovered from file command: . – the blank space before the period is the result of the output – i.e. blank. However the other side of the comparison uses purely the … Read more

How Do I Use Factory Girl To Generate A Paperclip Attachment?

You can use fixture_file_upload include ActionDispatch::TestProcess in your test helper, here is an example factory: include ActionDispatch::TestProcess FactoryBot.define do factory :user do avatar { fixture_file_upload(Rails.root.join(‘spec’, ‘photos’, ‘test.png’), ‘image/png’) } end end In the above example, spec/photos/test.png needs to exist in your application’s root directory before running your tests. Note, that FactoryBot is a new name … Read more

Rails 3 paperclip vs carrierwave vs dragonfly vs attachment_fu [closed]

I’ve used both Paperclip and Carrierwave, and if I were you, I’d go for Carrierwave. It’s a lot more flexible. I also love the fact that it doesnt clutter your models with configuration. You can define uploader classes instead. It allows you to easily reuse, extend etc your upload configuration. Did you watch the Carrierwave … Read more

Uploading multiple files with paperclip

Here is my code that worked well to upload multiple file using paperclip: We can achieve using nested attributes or using normal easy method. The following code shows normal method: User.rb has_many :images, :dependent => :destroy Image.rb has_attached_file :avatar, :styles => { :medium => “300×300>” } belongs_to :user users/views/new.html.erb <%= form_for @user, :html => { … Read more

rails paperclip and passenger `is not recognized by the ‘identify’ command`

This is related to ImageMagick. The command_path option needs to point to the location where identify is installed. From the command line, you can determine this with which identify. $ which identify /some/path/to/identify Afterwards, set command_path to that path (in config/environments/development.rb): Paperclip.options[:command_path] = “/some/path/to”

Paperclip exception : Paperclip::AdapterRegistry::NoHandlerError

This Error is raised because you aren’t giving Paperclip a correct class. It’s a just a String. You should receive something like this in params “asset”=> {“image”=> #<ActionDispatch::Http::UploadedFile:0x000000056679e8 @content_type=”image/jpg”, @headers= “Content-Disposition: form-data; name=\”asset[image]\”; filename=\”2009-11-29-133527.jpg\”\r\nContent-Type: image/jpg\r\n”, @original_filename=””2009-11-29-133527.jpg””, @tempfile=#<File:/tmp/RackMultipart20120619-1043-yvc9ox>>} And you should have something like this in yout View (in HAML, very simplified): = form_for @product, html: … Read more

Save image from URL by paperclip

In Paperclip 3.1.4 it’s become even simpler. def picture_from_url(url) self.picture = URI.parse(url) end This is slightly better than open(url). Because with open(url) you’re going to get “stringio.txt” as the filename. With the above you’re going to get a proper name of the file based on the URL. i.e. self.picture = URI.parse(“http://something.com/blah/avatar.png”) self.picture_file_name # => “avatar.png” … Read more