开发者

Python magic detects images just as 'binary'

In another question here I've read that python-magic should output the correct mime type of a file. I've added python-magic = 0.4.0 to my Django project, but here's what it detects:

In [2]: import magic
In [3]: m = magic.Magic(mime_encoding=True)
In [4]: m.from_file('/home/culebron/Documents/chapter2.pdf')
Out[4]: 'binary'

In [5]: m.from_file('/h开发者_StackOverflowome/culebron/bok.jpg')
Out[5]: 'binary'

What am I doing wrong?

I need to distinguish between images and other binary file types, without relying on file extensions. So, I want to take a file content and in the end get an information that it is either jpeg, or png, or audio or something else. It may be python-magic, or suggest another module if you know.

I've tried python-hachoir from pypi, but its documentation state is appaling, and I couldn't find anything useful examining their modules.


Looking at the examples in the readme, it seems that you need to use mime=True instead of mime_encoding=True to get the mime type.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜