Sending a file via curl to flask, flask shows no FileStorage objects in request.files

I am running a server with Flask using the following code:

from flask import Flask, flash, request, redirect, url_for
app = Flask(__name__)

@app.route('/', methods=['POST'])
def upload_file():
    # check if the post request has the file part
    return ""'', port=5000);

I run it with the command “python” where is the server code above. I am in a virtual environment with Flask installed.

In a separate shell on the same machine, at the command line, I run:

curl -F onlyFile=@test.dat

I expect to see something present and printed out in that first print statement, the one for request.files.__dict__.

Instead, I see this output:

 * Serving Flask app 'server2' (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on all addresses.
   WARNING: This is a development server. Do not use it in a production deployment.
 * Running on (Press CTRL+C to quit)
b'' - - [09/Sep/2021 18:58:41] "POST / HTTP/1.1" 200 -

This says to me that curl communicated to my server, and the server accepted the communication (200), but, the server didn’t put anything in request.files.__dict__.

Can anyone help me understand why this short Flask program isn’t communicating with curl in the way I expect?



Everything works as expected, except the way you try to read the data.

You need to access the data e.g. via request.files["onlyFile"].

request.files is not a standard Python dict, but an ImmutableMultiDict.

How do I know? I set a breakpoint and inspected the state of request.

That is not too hard – I did a 5 min lightning talk how to debug Flask applications: