How to find the mime type of a file in python?

Posted by Daren Thomas on Stack Overflow See other posts from Stack Overflow or by Daren Thomas
Published on 2008-09-04T12:07:27Z Indexed on 2010/05/02 12:07 UTC
Read the original article Hit count: 325

Filed under:
|

Let's say you want to save a bunch of files somewhere, for instance in BLOBs. Let's say you want to dish these files out via a web page and have the client automatically open the correct application/viewer.

Assumption: The browser figures out which application/viewer to use by the mime-type (content-type?) header in the HTTP response.

Based on that assumption, in addition to the bytes of the file, you also want to save the MIME type.

How would you find the MIME type of a file? I'm currently on a Mac, but this should also work on Windows.

Does the browser add this information when posting the file to the web page?

Is there a neat python library for finding this information? A WebService or (even better) a downloadable database?

Edit: Thank you, Dave Webb.

© Stack Overflow or respective owner

Related posts about python

Related posts about mime