Add note on data fields in multipart form encoding (#1022)

* Add note on data fields in multipart form encoding

* Fix message
This commit is contained in:
Florimond Manca 2020-06-15 20:40:17 +02:00 committed by GitHub
parent b481166481
commit 0f7d644b8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -463,6 +463,8 @@ MIME header field.
!!! tip
It is safe to upload large files this way. File uploads are streaming by default, meaning that only one chunk will be loaded into memory at a time.
Non-file data fields can be included in the multipart form using by passing them to `data=...`.
## Customizing authentication
When issuing requests or instantiating a client, the `auth` argument can be used to pass an authentication scheme to use. The `auth` argument may be one of the following...

View File

@ -191,6 +191,25 @@ of items for the file value:
}
```
If you need to include non-file data fields in the multipart form, use the `data=...` parameter:
```python
>>> data = {'message': 'Hello, world!'}
>>> files = {'file': open('report.xls', 'rb')}
>>> r = httpx.post("https://httpbin.org/post", data=data, files=files)
>>> print(r.text)
{
...
"files": {
"file": "<... binary content ...>"
},
"form": {
"message": "Hello, world!",
},
...
}
```
## Sending JSON Encoded Data
Form encoded data is okay if all you need is a simple key-value data structure.