How to get file mimetype in
Now get file mime type like below:
If you do not provide
If you are on
To solve the problem install
Or using
Read more here:
- https://github.com/ahupp/python-magic
#python #python_magic #magic #mimetype #mime #libmagic
Python
?pip install python-magic
Now get file mime type like below:
>>> magic.from_file("testdata/test.pdf", mime=True)
'application/pdf'
If you do not provide
mime=True
:>>> magic.from_file("testdata/test.pdf")
'PDF document, version 1.2'
If you are on
OS X
you may get the below error:ImportError: failed to find libmagic. Check your installation
To solve the problem install
libmagic
using brew
:brew install libmagic
Or using
macport
:port install file
Read more here:
- https://github.com/ahupp/python-magic
#python #python_magic #magic #mimetype #mime #libmagic
GitHub
GitHub - ahupp/python-magic: A python wrapper for libmagic
A python wrapper for libmagic. Contribute to ahupp/python-magic development by creating an account on GitHub.