The folder labeled content_type is invalid according to the application, but not

I am new to Paperclip and it all worked pretty fast. I am trying to get the user to only load PNG or JPG, although although I load JPG and my content_type checks JPG, it still says that it is not valid.

I tried to remove the PNG content_type, but to no avail.

I tried using has_attached_file, but it seems to be ignoring: content_type and stuff. Because if I download JPG only with :content_type => "image/png"; It doesn’t give an error.

Any suggestions?

    validates_attachment :avatar, :styles => { 
                                    :medium => "300x300", 
                                    :thumb => "100x100" 
                                }, :content_type => { 
                                    :content_type => "image/jpg", 
                                    :content_type => "image/png"
                                },
                                :size => { :in => 0..1.megabytes }

Oh, and while I am; I want my thumb and environment to be fixed. So no scaling, like 100x80, but only 100x100 anyway. How can i do this?

+4
3

, Paperclip validation, : - ,

:

validates_attachment_content_type :sound, :content_type => ['audio/mp3', 'application/x-mp3'], :if => :sound_attached?

lambda, , . :

   has_attached_file :attachment,
            styles:          lambda { |a| a.instance.is_image? ? {:small => "x200>", :medium => "x300>", :large => "x400>"}  : {:thumb => { :geometry => "100x100#", :format => 'jpg', :time => 10}, :medium => { :geometry => "300x300#", :format => 'jpg', :time => 10}}}

    def is_image?
            attachment.instance.attachment_content_type =~ %r(image)
    end

Lambda - , content-type , (I.E JPG). ( ), validates_attachment_content_type

+5

, , /jpeg image/jpg

 validates_attachment :avatar, :styles => { 
                                    :medium => "300x300", 
                                    :thumb => "100x100" 
                                }, :content_type => { 
                                    :content_type => "image/jpg",
                                    :content_type => "image/jpeg", 
                                    :content_type => "image/png"
                                },
                                :size => { :in => 0..1.megabytes }

, /^ image/, .

+3

I compared the log to the server and noticed different content headers. It should be "image / jpeg"

Parameters: {"avatar"=>#<ActionDispatch::Http::UploadedFile:0x0055b7d4c30870 @tempfile=#<Tempfile:/tmp/RackMultipart20170510-21515-11ld4ji.jpg>, @original_filename="IMAG0303.jpg", @content_type="multipart/form-data", @headers="Content-Disposition: form-data; name=\"avatar\"; filename=\"IMAG0303.jpg\"\r\nContent-Type: multipart/form-data\r\nContent-Length: 1057779\r\n">}

Parameters: {"avatar"=>#<ActionDispatch::Http::UploadedFile:0x0055b7d3ec3408 @tempfile=#<Tempfile:/tmp/RackMultipart20170510-21515-1l0x8sw.jpg>, @original_filename="2017.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"avatar\"; filename=\"photo_10/05/2017.jpg\"\r\nContent-Type: image/jpeg\r\n">}
0
source

All Articles