2

I am writing a server in python using Flask. And I know I am going to receive a request that it's type is multipart. These are the requests headers I receive from the post request:

Transfer-Encoding: chunked

Content-Length:

X-Data-Length: 8010

Host: ******

Content-Type: multipart/form-data; boundary=********

*This is how I receive the request:

@app.route('/***', methods == ['POST'])
    def some_function():
        print request.headers
        mp_data = decoder.MultipartDecoder.from_response(request)

        for part in multipart_data.parts:
            print(part.content)
            print(part.headers)

How am I supposed to retrieve the file sent to me in that request? I have tried using request-toolbelt MultipartDecoder but got lost trying to do so.

Any help solving this would be appreciated.

1 Answers1

0

If you mean to retrieve the file send from the client, you can use request.files, it's a dict that maps the name of upload field (<input type="file">) with the file object.

Grey Li
  • 11,664
  • 4
  • 54
  • 64