Skip to content
Myr

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

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Add note on data fields in multipart form encoding * Fix message

authored by Florimond Manca · committed by GitHub · parent b481166 · Browse files · 2 files+21 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+21 added−0 removed

  • other:+21 added−0 removed

2 files+21 added−0 removed

modified:docs/advanced.md+2 added
461 unmodified lines
462463!!! tip464 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.465 466 Non-file data fields can be included in the multipart form using by passing them to `data=...`.467468## Customizing authentication469470When 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...471
211 unmodified lines
modified:docs/quickstart.md+19 added
189 unmodified lines
190 ...191}192```193194If you need to include non-file data fields in the multipart form, use the `data=...` parameter:195196```python197>>> data = {'message': 'Hello, world!'}198>>> files = {'file': open('report.xls', 'rb')}199>>> r = httpx.post("https://httpbin.org/post", data=data, files=files)200>>> print(r.text)201{202 ...203 "files": {204 "file": "<... binary content ...>"205 },206 "form": {207 "message": "Hello, world!",208 },209 ...210}211```212213## Sending JSON Encoded Data214215Form encoded data is okay if all you need is a simple key-value data structure.216For more complicated data structures you'll often want to use JSON encoding instead.
256 unmodified lines