[Tutor] Determine Filetype

Emile van Sebille emile at fenx.com
Fri Sep 18 20:00:30 CEST 2009


On 9/18/2009 10:05 AM admin at gg-lab.net said...
> Hi,
> 
> i'm putting file in a DB as BLOB entries. To serve them, i need to
> take Content-Type headers.
> 
> So, i'm looking for a function that returnes the filetype, given a data str.
> 
> I've found many other topics like this in python mail-archive, but any
> of them contains the solution.
> 
> Can you help me, please?

I'd take a look at python-magic at 
http://hupp.org/adam/hg/python-magic/file/d3cd83e5a773 where the example 
shows that you can do:

# For MIME types
 >>> mime = magic.Magic(mime=True)
 >>> mime.from_file("testdata/test.pdf")
'application/pdf'


HTH,

Emile





> 
> Thankyou!
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 



More information about the Tutor mailing list