Suppose I have a StringIO file. How can I use python-magic to check its file type? [closed]
import StringIO
import magic
m = magic.Magic()
thefile = StringIO.StringIO(request.raw_post_data) # I got this from Django. ajax file uploader.
what now?
...should be as easy as:
>>> m.from_buffer(thefile.read(1024))
'PDF document, version 1.2'
It looks like you need to use the from_buffer method.
m.from_buffer(theFile)
精彩评论