volesen / kys

Know-your-student (kys)
https://verify.college
1 stars 0 forks source link

Restrict image format #15

Closed pierre-jezegou closed 1 month ago

pierre-jezegou commented 1 month ago

Rekognition only supports png and jpg file types https://docs.aws.amazon.com/rekognition/latest/dg/images-information.html So maybe we can restrict the user input

[ERROR] InvalidImageFormatException: An error occurred (InvalidImageFormatException) when calling the DetectText operation: Request has invalid image format
elliotverstraelen commented 1 month ago

This is taken care of in the feature/error-states branch:

def detect_faces(object_name):
    rekognition_client = boto3.client("rekognition")

    try:
        response = rekognition_client.detect_faces(
            Image={
                "S3Object": {
                    "Bucket": APP_BUCKET_NAME,
                    "Name": object_name,
                }
            },
            Attributes=["ALL"]
        )
    except rekognition_client.exceptions.InvalidImageFormatException as e:
        print(f"Invalid image format for {object_name}: {e}")
        return None, "invalid-image-format"
    except Exception as e:
        print(f"Error detecting faces: {e}")
        return None, f"error-detecting-faces: {e}"

    return len(response["FaceDetails"]), None