I'm using Quart (Flask fork) and I have a view which handles ".bin" file upload (100MB).
But on file.save(path) call I can see the file appears in destination folder for moment and immediately removed.
Can't get why it's happening.
View code:
@app.post("/settings/system-update")
async def system_update():
files = await request.files
update_img = files.get("update-img")
if update_img is None or update_img.filename == '':
logger.error(f"Update Image was not found in files: {files}")
await flash("Update Image was not found in uploaded files", "error")
return redirect(url_for("settings"))
# Create temporary directory if not exists
update_tmp_folder = os.path.join(config.TMP_DIR, "update")
os.makedirs(update_tmp_folder, exist_ok=True)
image_name = secure_filename(update_img.filename)
file_path = os.path.join(update_tmp_folder, image_name)
await update_img.save(file_path)
return redirect(url_for("settings"))
file_path returns correct path string.
I have @app.after_serving which has clean up logic but the code lines related to temp folder clean up are commented out (I had idea that temp content might be removed on server reload) as well as switching over use_reloader=False.
File uploaded via AJAX request without <form> tag:
<div class="input-group">
<input id="updateFileInput" class="form-control" type="file" name="update-img" data-update-url="{{ url_for('system_update') }}">
<button id="updateApplyBtn" class="btn btn-success" type="button">Start updating</button>
</div>
JS code:
// Update upload
$updateApplyBtn.on("click", function () {
var updateFile = $updateFileInput[0].files[0];
var formData = new FormData();
formData.append("update-img", updateFile);
$.ajax({
url: $updateFileInput.data("update-url"),
type: "POST",
data: formData,
contentType: false,
processData: false,
success: function (res) {
console.log(res)
}
});
});