Python: Check if uploaded file is jpg

前端 未结 5 1167
-上瘾入骨i
-上瘾入骨i 2020-12-05 03:20

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 F

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-05 03:58

    Use PIL. If it can open the file, it's an image.

    From the tutorial...

    >>> import Image
    >>> im = Image.open("lena.ppm")
    >>> print im.format, im.size, im.mode
    

提交回复
热议问题