I'm trying to convert my Flask server to Quart.
I have a form with file inputs in it, which I send over to the server. It used to work perfectly with Flask, but now I fail to send the files over.
Here's the code which worked:
app = Flask(__name__)
@app.route('/upload', methods=('POST',))
def process_form_data():
for name, file in request.files.items():
print(f'Processing {name}: {len(file.read())}')
return make_response(jsonify({"message": "File uploaded"}), 200)
The sending code is:
const request = new XMLHttpRequest();
function check_and_post(e) {
const formElement = e.target;
request.addEventListener("load", function (e) {
if (request.status == 200) {
window.location.href = '/work';
}
else {
alert('Error uploading file');
console.log(e);
}
});
// request error handler
request.addEventListener("error", function (e) {
alert('Error uploading files, try again.');
});
request.open("post", formElement.action);
request.responseType = "json";
request.send(new FormData(formElement));
}
My flask code consumed the files, and the load event was received with status 200.
My Quart code is as follows:
app = Quart(__name__)
@app.route('/upload', methods=('POST',))
async def process_form_data():
for name, file in (await request.files).items():
print(f'Processing {name}: {len(file.read())}')
return make_response(jsonify({"message": "File uploaded"}), 200)
Now I get to the "Error uploading file" branch, i.e. the request status received for the progress event isn't 200 (I didn't get any request for the error event).
The status of the request I now get in load is 413 (request too large?). The server side does not log any exception or warning.
Any idea?