Search code examples
pythonstringfilemime-typesstringio

Suppose I have a StringIO file. How can I use python-magic to check its file type?


import StringIO
import magic

m = magic.Magic()
thefile = StringIO.StringIO(request.raw_post_data)  # I got this from Django. ajax file uploader.

what now?


Solution

  • ...should be as easy as:

     >>> m.from_buffer(thefile.read(1024))
    'PDF document, version 1.2'