HTTP upload

This commit is contained in:
ABelliqueux 2022-11-08 16:55:32 +01:00
parent 894a4c5e76
commit c697953028
1 changed files with 7 additions and 5 deletions

12
app.py
View File

@ -171,7 +171,9 @@ def shutdown():
@app.route('/upload', methods=['GET', 'POST'])
@auth.login_required
def upload_file():
def upload_file(over_write=1):
if debug:
print("Existing files : {}".format(str(list_media_files(upload_folder))))
if request.method == "POST":
# Check if the post request has the file part
if "file" not in request.files:
@ -183,13 +185,13 @@ def upload_file():
return _("No selected file")
if file and allowed_ext(file.filename):
if debug:
print("Uploading file {} in {}.".format(str(file.filename, upload_folder)))
if file.filename not in list_media_files(upload_folder):
if debug:
print("Existing files : {}".format(str(list_media_files(upload_folder))))
print("Uploading file {} in {}.".format(str(file.filename.strip("/")), upload_folder))
if (file.filename.strip("/") not in list_media_files(upload_folder)) and over_write:
filename = secure_filename(file.filename)
file.save(os.path.join(upload_folder, filename))
return _("File saved in {}").format(upload_folder)
if debug:
print("File exists, skipping...")
return "File exists, skipping..."
return "OK"