Suppose I have a StringIO file. How can I use python-magic to check its file type? [closed]
-
10-10-2019 - |
Question
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'
OTHER TIPS
It looks like you need to use the from_buffer method.
m.from_buffer(theFile)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow