Supposons que j'ai un fichier StringIO. Comment puis-je utiliser la magie de python pour vérifier son type de fichier? [fermé]

StackOverflow https://stackoverflow.com/questions/4677575

Question

import StringIO
import magic

m = magic.Magic()
thefile = StringIO.StringIO(request.raw_post_data)  # I got this from Django. ajax file uploader.

Et maintenant?

Était-ce utile?

La solution

... doit être aussi simple que:

 >>> m.from_buffer(thefile.read(1024))
'PDF document, version 1.2'

Autres conseils

Il semble que vous devez utiliser la méthode from_buffer.

m.from_buffer(theFile)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top