I need to have the ability to upload files on the server but before uploading I would like to verify this file whether this file is and image or a script called image.jpeg.
For this I'm using a library called python-magic
import magic
attachment = request.FILES['file'].read()
m = magic.open(magic.MAGIC_MIME_TYPE)
m.load()
ft = m.buffer(attachment)
m.close()
Its working fine for me. But should I read whole file?
attachment = request.FILES['file'].read()
I think that this is a bad idea so my question is how much header of file weight? So than i can read only couple bytes and verify files mime-type.