Check if file from incoming request is an image

Viewed 218
1 Answers

Given a bytes object, the following solution worked out for me:

def validate_image(bytes_object):
    import io
    from PIL import Image
    try:
        Image.open(io.BytesIO(bytes_array))
    except OSError:
        print('Not a valid image')
Related