Paperclip Audio file upload
ruby-on-rails
Solution
This will work for any type of the file
validates_attachment_content_type :avatar, :content_type => /.*/
You can also discover exact content type of the file with command
file -i path/to/file # or
file --mime-type path/to/file
I have run in on MP3 file and it returned
audio/mpeg
So if you want to validate only some set of content types you can add 'audio/mpeg' to the list
validates_attachment_content_type :avatar, :content_type => [ ..., 'audio/mpeg', ...]
Problem
I am using paperclip gem to upload files. I want to upload different kinds of files like pdf, doc, video and audio. I have validation for file type in my model. For doc, pdf and Video it is working but it is not wroking for audio file. please help. My model ``` class Xyz < ActiveRecord::Base attr_accessible :email, :name, :avatar, :CategoryID has_attached_file :avatar validates_attachment_content_type :avatar, :content_type => ['video/mp4','video/avi','Audio/mp3','application/pdf',"application/pdf","application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "text/plain"] #validates_attachment_content_type :avatar, :content_type => ['audio/mp3'] end ``` This is the error I got... ``` 1 error prohibited this xyz from being saved: Avatar content type is invalid ```