views:

1125

answers:

4

Hey everyone,

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.

+1  A: 

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 :-)

zoltarSpeaks
+1  A: 

Wrong content type? Try audio/mpeg.

http://www.w3schools.com/media/media%5Fmimeref.asp

LymanZerga
Well the array of content types i went with initially to allow was:[ 'application/mp3', 'application/x-mp3', 'audio/mpeg', 'audio/mp3' ],However the content type getting saved to the database was 'audio/mpg' which i thought was odd. So is there something dodgy about my mp3's or something else weird going on? This does seem odd.
zoltarSpeaks
A: 

My browser recognized it as "audio/mpeg3".

Filip
A: 

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.

Filip
I agree, i think it's going to be a case of building up an array of content_types that are all valid for an mp3 to cover all bases.
zoltarSpeaks