Kalyani
Kalyani

Reputation: 31

Imagemagic gives me error while uploading a .txt or a .html file, whereas i can successfull upload a image(.png, .jpeg)

Imagemagic gives me error while uploading a .txt or a .html file, whereas I can successfully upload a image(.png, .jpeg)

Error: Project files files

Paperclip::Errors::NotIdentifiedByImageMagickError

Model Code:

class ProjectFile < ActiveRecord::Base
  belongs_to :project
  has_attached_file :files, :styles => {:medium=>"300x300>",:thumb=>"100x100>"},
                            :storage => :s3,
                            :s3_credentials => File.join(Rails.root, 'config', 'aws.yml'), 
                            :path => ":class/:attachment/:id/:style.:extension"
end

Can anyone help me out with error.

Upvotes: 0

Views: 98

Answers (2)

Kalyani
Kalyani

Reputation: 31

Hey I resolved the issue, I was uploading a .txt and .pdf file and i had specified styles attribute while uploading the file. Following is code:

class ProjectFile < ActiveRecord::Base

belongs_to :project

has_attached_file :files,

                           :storage => :s3,

                           :s3_credentials => File.join(Rails.root, 'config', 'aws.yml'),
                           :path => ":class/:attachment/:id/:style.:extension"

end

Removing style attribute resolved my problem. :)

Upvotes: 1

Maxim
Maxim

Reputation: 9961

Paperclip can't calculate size (geometry) of not image files (see it here) and raise exception.

In you case you should specify content type filter as described here to allow uploading of image files only.

Upvotes: 1

Related Questions