[Tutor] Determine Filetype

admin at gg-lab.net admin at gg-lab.net
Fri Sep 18 20:21:36 CEST 2009


Hi Emile,

that functions requires a filename/path. Just like this one (for images)

http://docs.python.org/library/imghdr.html

Ok, i don't have a filename. I get the file from a BLOB in a db. Any idea?

Thankyou for your precious help.

2009/9/18 Emile van Sebille <emile at fenx.com>:
> 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
>>
>
> _______________________________________________
> 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