I'm very interested to hear of your experience with MIME types and browsers. I've just written an audio_player extension[1], which uses paperclip to deal with attaching audio files. The flash player that I'm using can only play mp3s, so I want to limit the MIME type to that format. I've set up some validation in the model, as follows:

        
http://github.com/nelstrom/radiant-audio_player-extension/tree/master/app/models/audio.rb#L12-14

I was quite puzzled when I tested the attachment of an mp3 file to an Audio model. Using the exact same mp3 file, I tried creating the model through the Radiant admin (in the browser), and I tried doing it through script/console (at the command line). I was able to attach the MP3 file by both methods, but found that the MIME type was saved as audio/mpeg when I uploaded through the browser, and as application/x- mp3 when created at the console. So it does look as though the browser is... opinionated, when it comes to mime types.

Luckily, paperclip seems to be happy with both of these formats, but I did have to broaden the conditions for my model validation to let both of these through.

Cheers,
Drew

[1]: http://github.com/nelstrom/radiant-audio_player-extension/tree


On 21 Oct 2008, at 22:05, justin blecher wrote:

jeff,

it's been my experience that the browser cannot be trusted for sending
the correct mime type upon upload. firefox (all platforms) has been a
particularly bad offender, and i know that IE does some funny stuff,
too. (i can't believe it's 2008 and this basic functionality is still
broken! on second thought, i can. mime types and file extensions have
always been like the wild-west.)

in our recent projects that involve uploading files, we've used
mimetype-fu <http://github.com/mattetti/mimetype-fu/> for determining
the correct/canonical (as far as mimetype-fu is concerned) mime type
to avoid two situations: 1) new/unexpected file types that users
upload and 2) consistent mapping of common file types
(application/msword vs. application/vnd.ms-word vs. ???)

maybe paperclip should be patched to use mimetype-fu. it's pretty
inadequate for anything other than basic file types at the moment:

   # Infer the MIME-type of the file from the extension.
   def content_type
type = (self.path.match(/\.(\w+)$/)[1] rescue "octet- stream").downcase
     case type
     when %r"jpe?g"                 then "image/jpeg"
     when %r"tiff?"                 then "image/tiff"
     when %r"png", "gif", "bmp"     then "image/#{type}"
     when "txt"                     then "text/plain"
     when %r"html?"                 then "text/html"
     when "csv", "xml", "css", "js" then "text/#{type}"
     else "application/x-#{type}"
     end
   end

probably not the answer you're looking for, but hth,

-justin


On Tue, Oct 21, 2008 at 1:32 PM, Jeffrey Jones <[EMAIL PROTECTED]> wrote:
Finally figured out what it was.

My version of Firefox (Firefox on Kubuntu linux) didn't know the video/x-flv mime-type so when it uploaded the file it was setting the content type as application/octet-stream. It appears paperclipped uses the browser mime-type to determine if the file is allowed to be uploaded or not (I assumed it
checked the file).

Adding the mime-type to Firefox solved the issue.

On Kubuntu create a ~/.mime.types file with

video/x-flv                flv

(The master mime-type file is /etc/mime.types)

I do not know if this affects windows Firefox or how you would add the
mime-type in windows.

Cheers

Jeff

Jeffrey Jones wrote:

Hoi all.

Has anyone managed to upload flash video files using the paperclipped extension? I added video/x-flv to the allowed mime types but the FLVs are
still getting rejected as not allowed.
_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

_______________________________________________
Radiant mailing list
Post:   Radiant@radiantcms.org
Search: http://radiantcms.org/mailing-list/search/
Site:   http://lists.radiantcms.org/mailman/listinfo/radiant

Reply via email to