Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

do_not_validate_attachment_file_type still validating #2195

Closed
persep opened this issue May 6, 2016 · 2 comments
Closed

do_not_validate_attachment_file_type still validating #2195

persep opened this issue May 6, 2016 · 2 comments

Comments

@persep
Copy link

persep commented May 6, 2016

Hi,
I have Ubuntu 14.0.4 64 with rails 4.26 and paperclip 4.3.6.
I have a model called track in track.rb with a do_not_validate_attachment_file_type validation:

class Track < ActiveRecord::Base
    has_many :tracksegments, :dependent => :destroy
    has_many :points, :through => :tracksegments

    has_attached_file :gpx
    validates :name, presence: true
    do_not_validate_attachment_file_type :gpx

    before_save :parse_file
       ...............

According to the docs it shouldn't do any validations but when I load a gps file i get the error
[paperclip] Content Type Spoof: Filename demofile.foo (text/xml from Headers, [] from Extension), content type discovered from file command: application/xml. See documentation to allow this combination.
The only way to bypass the validation is with an initialier in config/initializer/paperclip.rb with:
Paperclip.options[:content_type_mappings] = { :gpx => ["application/xml"] }

Souldn't do_not_validate_attachment_file_type stop all validations?

@persep
Copy link
Author

persep commented May 6, 2016

i've just discovered that for do_not_validate_attachment_file_type to stop the validation you have to add an initializer in config/initializer/paperclip.rb
with
Paperclip::Attachment.default_options[:validate_media_type] = false
I couln't find this in the docs only in the NEWS file

@persep persep closed this as completed May 6, 2016
matthewford added a commit to matthewford/mastodon that referenced this issue Dec 10, 2022
Specs were failing due to paperclips' do_not_validate_attachment_file_type option not working properly

thoughtbot/paperclip#2195

Paperclip: validate_media_type: false also broke the specs as it still expects a filename validation.

So adding in a validation to appease paperclips requirements.
tenderlove pushed a commit to tenderlove/mastodon that referenced this issue Jan 4, 2023
Specs were failing due to paperclips' do_not_validate_attachment_file_type option not working properly

thoughtbot/paperclip#2195

Paperclip: validate_media_type: false also broke the specs as it still expects a filename validation.

So adding in a validation to appease paperclips requirements.
jordemort pushed a commit to jordemort/mastodon that referenced this issue Jan 20, 2023
Specs were failing due to paperclips' do_not_validate_attachment_file_type option not working properly

thoughtbot/paperclip#2195

Paperclip: validate_media_type: false also broke the specs as it still expects a filename validation.

So adding in a validation to appease paperclips requirements.
inductor pushed a commit to inductor/mastodon that referenced this issue Jan 31, 2023
Specs were failing due to paperclips' do_not_validate_attachment_file_type option not working properly

thoughtbot/paperclip#2195

Paperclip: validate_media_type: false also broke the specs as it still expects a filename validation.

So adding in a validation to appease paperclips requirements.
tenderlove pushed a commit to tenderlove/mastodon that referenced this issue Feb 13, 2023
Specs were failing due to paperclips' do_not_validate_attachment_file_type option not working properly

thoughtbot/paperclip#2195

Paperclip: validate_media_type: false also broke the specs as it still expects a filename validation.

So adding in a validation to appease paperclips requirements.
@duhaime
Copy link

duhaime commented Mar 27, 2023

Adding

Paperclip::Attachment.default_options[:validate_media_type] = false

Is not a great idea because it's going to allow all of your attachments to possess any media type (e.g. sketchy.exe will be allowed). It's better to add validate_media_type: false to the has_attached_file block

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants