Re: [flask] Wrong mimetype of uploaded mp3 files?
- From:
- Armin Ronacher
- Date:
- 2011-03-10 @ 14:44
Hi,
On 3/10/11 2:51 AM, Christoph Heer wrote:
> I writting a little flask app with a file upload formular. If the file
> an mp3 file than is request.files['audio_file'].content_type =
> audio/mp3 but normaly the correct mimetype of a mp3 file should be
> audio/mpeg or? I save the mimetype and the file in a gridfs storage of
> mongodb and want to get over the mimetype the correct file extention
> but the mimetype modul of python doesn't has an extention for the
> mimetype of audio/mp3.
The mimetype transmitted comes from the browser (if at all). Most
browsers are not even transmitting a mimetype.
We recommend using the file extension instead.
Regards,
Armin
Re: [flask] Wrong mimetype of uploaded mp3 files?
- From:
- Rob Mela
- Date:
- 2011-03-16 @ 11:40
Most media files will have "magic numbers" - a sequence of bytes, usually
at the start of a file header -- that will give a pretty reliable idea of
what media type the file is. So the possibility exists of looking at the
first few bytes of an upload stream.
The Wikipedia article on "Magic Number" provides some examples. GIF
files for example always start with "GIF89a" or "GIF87a".
I keep meaning to look at the code for Apache code mod_mime_magic or the
Unix "file" command to see how they organize all that info.
Den Mar 10, 2011 kl. 9:44 AM skrev Armin Ronacher:
The mimetype transmitted comes from the browser (if at all). Most
browsers are not even transmitting a mimetype.
We recommend using the file extension instead.
Regards,
Armin