Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paperclip Gem - "Image has contents that are not what they are reported to be" Error

The website's function is to post a Blog Post. It's running locally on Windows 7. I've tried on Paperclip gem (both versions 4.2.4 and 4.3) and the server goes into an infinite loop in cmd (doesn't happen on 4.2.4 but still get the error). I did bundle install and it's definitely installed.

Gemfile:

gem "paperclip", "~> 4.3"

Here's the model:

class Post < ActiveRecord::Base

    has_attached_file :image, :default_url => ":style/rails1.jpg"
    validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/

end

This is the error I get when trying to submit an image (png or jpg):

Image has contents that are not what they are reported to be

I'm new to this so detailed explanations would be appreciated. I read some other fixes on here but nothing worked.

like image 882
James Mitchell Avatar asked Jul 23 '15 20:07

James Mitchell


2 Answers

The correct way disable spoof checking is to use: validate_media_type: false in your attachment definition i.e.

has_attached_file :image, :default_url => ":style/rails1.jpg", validate_media_type: false
like image 96
Vedant Agarwala Avatar answered Oct 21 '22 22:10

Vedant Agarwala


Figured out a temporary solution:

Add this file

config/initializers/paperclip_media_type_spoof_detector_override.rb

require 'paperclip/media_type_spoof_detector'
module Paperclip
  class MediaTypeSpoofDetector
    def spoofed?
      false
    end
  end
end
like image 7
James Mitchell Avatar answered Oct 21 '22 23:10

James Mitchell