deojeff
deojeff

Reputation: 377

Handling multipart/form-data with Python

I am trying to get the value of a POST with multipart/form-data to my backend.

Making the request:

files = {
    'image': ('youtried.jpg', (open('youtried.jpg', 'rb')), 'image/jpg', {'Expires': '0'}),
    'name': 'Deojeff'
}

r = requests.post('http://localhost/service/images', files=files)

print (r.text)

Handling the request:

def on_post(self, req, resp):
    """Creates an image."""
    x = req.stream.read()

    base64.b64encode(x)

    helpers.write_json(resp, falcon.HTTP_200, {
        'name': str(x)
    })

How to get the value of 'name' ( in this case the value is 'Deojeff' ) in the on_post method of my class?

Upvotes: 0

Views: 3346

Answers (1)

edge
edge

Reputation: 31

Try:

req.get_param('name')

returns the value of the param 'name'. Use req.params() to get the list of all the params with values.

Upvotes: 1

Related Questions