Skip to content

Instantly share code, notes, and snippets.

@jeff1evesque
Created March 1, 2015 19:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeff1evesque/9eb148921f7bbfa7ff30 to your computer and use it in GitHub Desktop.
Save jeff1evesque/9eb148921f7bbfa7ff30 to your computer and use it in GitHub Desktop.
Check file mimetype
## 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