Améliore message d'erreur si upload image invalide

This commit is contained in:
Emmanuel Viennet 2021-09-24 00:47:06 +02:00
parent 9c5408f503
commit 36c7358eed
2 changed files with 7 additions and 1 deletions

View File

@ -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

View File

@ -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
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