master
mb 2 years ago
parent 1adac60073
commit 8cf89d550a

@ -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)

Loading…
Cancel
Save