From 2b967ba34eb3e58e2d977d6a2f1374d92a1d8218 Mon Sep 17 00:00:00 2001 From: Emmanuel Viennet Date: Mon, 26 Jul 2021 16:23:07 +0300 Subject: [PATCH] Fix: change photo --- app/scodoc/sco_photos.py | 6 +++--- app/views/scolar.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/scodoc/sco_photos.py b/app/scodoc/sco_photos.py index 7ccf159fb..5c1cfacfb 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 2cd85a762..d5bf596a5 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)