Last active
September 22, 2022 07:52
-
-
Save cbwar/0aea77973855c9cb07a74359e61f8e4d to your computer and use it in GitHub Desktop.
Python: Get mime type from file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/43580/how-to-find-the-mime-type-of-a-file-in-python | |
import magic | |
mime = magic.Magic(mime=True) | |
mime.from_file("testdata/test.pdf") # 'application/pdf' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Handy function but DON'T USE THIS TO DETERMINE THE TRUE MIMETYPE OF A FILE!!! You can easily rename a file extension.