Brosef Brosef - 1 year ago 89
Python Question

view multipart form request parameter values using flask

I'm uploading a file to my flask backend and I can't figure out how to access the parameter values in the multipart form.

I can access the uploaded file easily by doing

file = request.files['file']
but can't figure out a way to get the parameter values.

I've tried the following but haven't had any luck:


Answer Source

Most form inputs can be retrieved as follows:


Files can be accessed via


Where the fieldnames are the name attribute in the HTML.

Keep in mind that, just because there's a result for request.files.get("someName") doesn't mean a file was actually uploaded. You should check that the filename exists, too, in order to validate if a file was indeed uploaded.

Take for example, the following HTML

<form action="/form_endpoint" method="POST">
  <input type="text" name="data">
  <input type="submit" value="submit">

You would access the value the user input in the data field by data = request.form.get("data")