From cd663087c867ed9c2af79ad1a8c7accba0c1e14d Mon Sep 17 00:00:00 2001 From: n07070 Date: Mon, 9 May 2022 01:49:57 +0200 Subject: [PATCH] Fixed printing images from AJAX calls --- src/main.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main.py b/src/main.py index fbffff9..57ee70c 100644 --- a/src/main.py +++ b/src/main.py @@ -122,17 +122,24 @@ def api_print_image(): sign = request.form["signature"] except Exception as e: flash(str(e),'error') - redirect(url_for('index')) + app.logger.error(str(e) + " - Whoops, no forms submitted or missing signature.") + return redirect(url_for('index')) if request.method == 'POST': # check if the post request has the file part - - if 'img' not in request.files: - flash('No file found. Did you use the good form ?', 'error') - return redirect(url_for("index")) - else: - file = request.files['img'] - + try: + if 'img' not in request.files: + flash('No file found. Did you use the good form ?', 'error') + app.logger.error("No file found. Did you use the good form ?") + return redirect(url_for("index")) + else: + file = request.files['img'] + except Exception as e: + if sign is not None and photo is not None: + pass + else: + flash(str(e), 'error') + app.logger.error("Couldn't get an image nor signature : " + str(e)) # If the user does not select a file, the browser submits an # empty file without a filename.