Struggling to workout when i add the following validtion to my Voice model using paperclip, it is being triggered when i try and upload an 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 have tried a number of different mp3 files but none of them seem to upload because the validation is failing.
Wrong content type? Try audio/mpeg.
http://www.w3schools.com/media/media_mimeref.asp
Just being silly, sorry.
I simply removed the validation, viewed in the db what the content_type was being saved as ('audio/mpg') and added it to the aray of allowed content_types in the validation.
Job done :-)
For an (hopefully) complete mp3-support I used the following mimetypes:
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' ]
Yes, but If a user has other browser (or other version of browser) mp3's content type could be interpreted in unexpected way and he will not have the ability to save mp3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With