Améliore message d'erreur si upload image invalide
This commit is contained in:
parent
9c5408f503
commit
36c7358eed
@ -230,6 +230,7 @@ def scodoc7func(func):
|
|||||||
if arg_name == "REQUEST": # special case
|
if arg_name == "REQUEST": # special case
|
||||||
pos_arg_values.append(REQUEST)
|
pos_arg_values.append(REQUEST)
|
||||||
else:
|
else:
|
||||||
|
# peut produire une KeyError s'il manque un argument attendu:
|
||||||
v = req_args[arg_name]
|
v = req_args[arg_name]
|
||||||
# try to convert all arguments to INTEGERS
|
# try to convert all arguments to INTEGERS
|
||||||
# necessary for db ids and boolean values
|
# necessary for db ids and boolean values
|
||||||
|
@ -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 datetime
|
||||||
import glob
|
import glob
|
||||||
import io
|
import io
|
||||||
@ -52,6 +53,7 @@ import requests
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
|
import PIL
|
||||||
from PIL import Image as PILImage
|
from PIL import Image as PILImage
|
||||||
|
|
||||||
from flask import request, g
|
from flask import request, g
|
||||||
@ -246,7 +248,10 @@ def store_photo(etud, data):
|
|||||||
filesize = len(data)
|
filesize = len(data)
|
||||||
if filesize < 10 or filesize > MAX_FILE_SIZE:
|
if filesize < 10 or filesize > MAX_FILE_SIZE:
|
||||||
return 0, "Fichier image de taille invalide ! (%d)" % filesize
|
return 0, "Fichier image de taille invalide ! (%d)" % filesize
|
||||||
|
try:
|
||||||
filename = save_image(etud["etudid"], data)
|
filename = save_image(etud["etudid"], data)
|
||||||
|
except PIL.UnidentifiedImageError:
|
||||||
|
raise ScoGenError(msg="Fichier d'image invalide ou non format non supporté")
|
||||||
# update database:
|
# update database:
|
||||||
etud["photo_filename"] = filename
|
etud["photo_filename"] = filename
|
||||||
etud["foto"] = None
|
etud["foto"] = None
|
||||||
|
Loading…
Reference in New Issue
Block a user