How can I check if a file uploaded by a user is a real jpg file in Python (Google App Engine)?
This is how far I got by now:
Script receives image via HTML Form Post and is processed by the following code
... incomming_image = self.request.get('img') image = db.Blob(incomming_image) ...
I found mimetypes.guess_type, but it does not work for me.
If you need more than looking at extension, one way would be to read the JPEG header, and check that it matches valid data. The format for this is:
so a quick recogniser would be:
However this won’t catch any bad data in the body. If you want a more robust check, you could try loading it with PIL. eg: