Created
March 1, 2015 19:22
-
-
Save jeff1evesque/9eb148921f7bbfa7ff30 to your computer and use it in GitHub Desktop.
Check file mimetype
This file contains hidden or 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
## this snippet requires `sudo pip install python-magic` | |
import magic | |
acceptable_type = ['text/plain', 'text/csv', 'text/xml', 'application/xml'] | |
mimetype = magic.from_file( file, mime=True ) | |
# validate mimetype | |
if ( mimetype not in acceptable_type ): print 'Invalid mimetype' | |
else: print 'Valid mimetype' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment