From 36c7358eed8bced95f86b776016e43cbd2cf1c17 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Fri, 24 Sep 2021 00:47:06 +0200 Subject: [PATCH] =?UTF-8?q?Am=C3=A9liore=20message=20d'erreur=20si=20uploa?= =?UTF-8?q?d=20image=20invalide?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/decorators.py | 1 + app/scodoc/sco_photos.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/decorators.py b/app/decorators.py index 9f30bead2..a32805bba 100644 --- a/app/decorators.py +++ b/app/decorators.py @@ -230,6 +230,7 @@ def scodoc7func(func): if arg_name == "REQUEST": # special case pos_arg_values.append(REQUEST) else: + # peut produire une KeyError s'il manque un argument attendu: v = req_args[arg_name] # try to convert all arguments to INTEGERS # necessary for db ids and boolean values diff --git a/app/scodoc/sco_photos.py b/app/scodoc/sco_photos.py index 286314bf7..1e24c6dff 100644 --- a/app/scodoc/sco_photos.py +++ b/app/scodoc/sco_photos.py @@ -43,6 +43,7 @@ Les images sont servies par ScoDoc, via la méthode getphotofile?etudid=xxx """ +from app.scodoc.sco_exceptions import ScoGenError import datetime import glob import io @@ -52,6 +53,7 @@ import requests import time import traceback +import PIL from PIL import Image as PILImage from flask import request, g @@ -246,7 +248,10 @@ def store_photo(etud, data): filesize = len(data) if filesize < 10 or filesize > MAX_FILE_SIZE: return 0, "Fichier image de taille invalide ! (%d)" % filesize - filename = save_image(etud["etudid"], data) + try: + filename = save_image(etud["etudid"], data) + except PIL.UnidentifiedImageError: + raise ScoGenError(msg="Fichier d'image invalide ou non format non supporté") # update database: etud["photo_filename"] = filename etud["foto"] = None