diff --git a/app/scodoc/sco_photos.py b/app/scodoc/sco_photos.py index 7ccf159f..5c1cfacf 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 """ +import io import os import time import datetime @@ -51,7 +52,6 @@ import six.moves.urllib.request, six.moves.urllib.error, six.moves.urllib.parse import traceback from PIL import Image as PILImage -from io import StringIO import glob from flask import request @@ -238,7 +238,7 @@ def photo_pathname(context, etud, size="orig"): def store_photo(context, etud, data, REQUEST=None): """Store image for this etud. If there is an existing photo, it is erased and replaced. - data is a string with image raw data. + data is a bytes string with image raw data. Update database to store filename. @@ -296,7 +296,7 @@ def save_image(context, etudid, data): Save image in JPEG in 2 sizes (original and h90). Returns filename (relative to PHOTO_DIR), without extension """ - data_file = StringIO() + data_file = io.BytesIO() data_file.write(data) data_file.seek(0) img = PILImage.open(data_file) diff --git a/app/views/scolar.py b/app/views/scolar.py index 2cd85a76..d5bf596a 100644 --- a/app/views/scolar.py +++ b/app/views/scolar.py @@ -791,7 +791,7 @@ def formChangePhoto(context, etudid=None, REQUEST=None): elif tf[0] == -1: return REQUEST.RESPONSE.redirect(dest_url) else: - data = tf[2]["photofile"][0].read() + data = tf[2]["photofile"].read() status, diag = sco_photos.store_photo(context, etud, data, REQUEST=REQUEST) if status != 0: return REQUEST.RESPONSE.redirect(dest_url)