Paperclip validates_attachment_content_type for mp3 called when connecting mp3

The fight for training, when I add the following version for my Voice model using paperclip, it starts when I try to download mp3:

class Voice < ActiveRecord::Base has_attached_file :clip validates_attachment_presence :clip validates_attachment_content_type :clip, :content_type => [ 'application/mp3', 'application/x-mp3', 'audio/mpeg', 'audio/mp3' ], :message => 'file must be of filetype .mp3' validates_attachment_size :clip, :less_than => 10.megabytes validates_presence_of :title end 

I tried several different mp3 files, but none of them are downloaded, because the check is not performed.

+7
validation ruby-on-rails mp3 paperclip
source share
5 answers

Just be stupid, sorry.

I simply deleted the check by looking in db that the content_type was saved as ('audio / mpg') and adding it to the list of allowed content_types in the validation.

The task: -)

+4
source share

Invalid content type? Try audio / mpeg.

http://www.w3schools.com/media/media_mimeref.asp

+4
source share

For (hopefully) full mp3 support, I used the following mimetypes types:

 validates_attachment_content_type :audio, :content_type => [ 'audio/mpeg', 'audio/x-mpeg', 'audio/mp3', 'audio/x-mp3', 'audio/mpeg3', 'audio/x-mpeg3', 'audio/mpg', 'audio/x-mpg', 'audio/x-mpegaudio' ] 
+3
source share

Yes, but if the user has another browser (or another version of the browser), the type of mp3 content can be interpreted in an unexpected way, and he will not be able to save mp3.

+1
source share

So, oddly enough, I had this problem today, and none of the above solutions worked for me. I was getting this error:

 `[paperclip] Content Type Spoof: Filename blah_blah_blah.mp3 (audio/mp3 from Headers, ["audio/mpeg"] from Extension), content type discovered from file command: application/octet-stream. See documentation to allow this combination.` 

I solved this using this as my validator:

 validates_attachment_content_type :recording, content_type: [ 'application/mp3', 'application/x-mp3', 'audio/mpeg', ['audio/mpeg'], # note the array around the type 'audio/mp3' ], message: 'File must be of filetype .mp3' 

Hope this helps someone.

0
source share

All Articles