Usually I would download it to StringIO object, then run this:
m = magic.Magic()
m.from_buffer(thefile.read(1024))
But this time , I can’t download the file, because the image might be 20 Megabytes. I want to use Python magic to find the file type without downloading the entire file.
If python-magic can’t do it…is the next best way to observe the mime type in the headers? But how accurate is this??
I need accuracy.
You can call
read(1024)without downloading the whole file:Then, just use your existing code.
urlopenreturns a file-like object, so this works naturally.