HTTP upload
This commit is contained in:
parent
894a4c5e76
commit
c697953028
12
app.py
12
app.py
|
@ -171,7 +171,9 @@ def shutdown():
|
||||||
|
|
||||||
@app.route('/upload', methods=['GET', 'POST'])
|
@app.route('/upload', methods=['GET', 'POST'])
|
||||||
@auth.login_required
|
@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":
|
if request.method == "POST":
|
||||||
# Check if the post request has the file part
|
# Check if the post request has the file part
|
||||||
if "file" not in request.files:
|
if "file" not in request.files:
|
||||||
|
@ -183,13 +185,13 @@ def upload_file():
|
||||||
return _("No selected file")
|
return _("No selected file")
|
||||||
if file and allowed_ext(file.filename):
|
if file and allowed_ext(file.filename):
|
||||||
if debug:
|
if debug:
|
||||||
print("Uploading file {} in {}.".format(str(file.filename, upload_folder)))
|
print("Uploading file {} in {}.".format(str(file.filename.strip("/")), upload_folder))
|
||||||
if file.filename not in list_media_files(upload_folder):
|
if (file.filename.strip("/") not in list_media_files(upload_folder)) and over_write:
|
||||||
if debug:
|
|
||||||
print("Existing files : {}".format(str(list_media_files(upload_folder))))
|
|
||||||
filename = secure_filename(file.filename)
|
filename = secure_filename(file.filename)
|
||||||
file.save(os.path.join(upload_folder, filename))
|
file.save(os.path.join(upload_folder, filename))
|
||||||
return _("File saved in {}").format(upload_folder)
|
return _("File saved in {}").format(upload_folder)
|
||||||
|
if debug:
|
||||||
|
print("File exists, skipping...")
|
||||||
return "File exists, skipping..."
|
return "File exists, skipping..."
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue