From 8cf89d550ac71b6cb4e7af2fa5ea80ee0895fe79 Mon Sep 17 00:00:00 2001 From: mb Date: Tue, 6 Jun 2023 14:41:12 +0200 Subject: [PATCH] changes! --- week5/app.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/week5/app.py b/week5/app.py index aac2c67..2aa9e81 100644 --- a/week5/app.py +++ b/week5/app.py @@ -6,7 +6,7 @@ from flask import render_template import glob import os -UPLOAD_FOLDER = ".\static\img\\" +UPLOAD_FOLDER = os.path.join("static", "img") ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'} def allowed_file(filename): return '.' in filename and \ @@ -36,11 +36,23 @@ from flask import request def upload_file(): if request.method == 'POST': file = request.files['tile'] - overwrite = request.form["overwrite"] if file and allowed_file(file.filename): filename, fileextension = os.path.splitext(file.filename) - file.save(os.path.join(app.config['UPLOAD_FOLDER'], (overwrite + fileextension) )) + overwrite = request.form["overwrite"] + + input_file_path = os.path.join(app.config['UPLOAD_FOLDER'], (filename, fileextension)) + overwritten_file_path = os.path.join(app.config['UPLOAD_FOLDER'], (overwrite, '.png')) + + print("[input file path]:", input_file_path) + print("[overwritten file path]:", overwritten_file_path) + + if 'png' not in fileextension: + print("--- convert uploaded image to png") + cmd = f"convert { input_file_path } { overwritten_file_path }" + os.system(cmd) + + file.save(overwritten_file_path) # print("==============================================================") # print(fileextension)