Paperclip Gem - "Image has content that is not what is reported to be" Error

The function of the website is to post a blog post. It runs locally on Windows 7. I tried Paperclip on an airplane (both versions 4.2.4 and 4.3), and the server goes into an endless loop in cmd (does not happen in 4.2.4, but still gets an error). I installed the package and it is definitely installed.

Gemfile:

gem "paperclip", "~> 4.3" 

Here is 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 send an image (png or jpg):

The image has content that is not what they report.

I am new to this, so detailed explanations will be appreciated. I read some other corrections here, but nothing worked.

+5
source share
3 answers

Workaround Revealed:

Add this file

configurations / initializers / paperclip_media_type_spoof_detector_override.rb

 require 'paperclip/media_type_spoof_detector' module Paperclip class MediaTypeSpoofDetector def spoofed? false end end end 
+4
source

The proper way to 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 
+2
source

This is not the best way. But this method is a bit safer and fewer monkey patches ...
Just add this to your model:

 do_not_validate_attachment_file_type :image 
+1
source

All Articles