Skip to content

Commit 0e1387d

Browse files
committed
Fix docs for client uploading
1 parent 67225a5 commit 0e1387d

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

docs/client.rst

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -234,32 +234,17 @@ To upload Multipart-encoded files::
234234
>>> url = 'http://httpbin.org/post'
235235
>>> files = {'file': open('report.xls', 'rb')}
236236

237-
>>> r = yield from aiohttp.request('post', url, data=files)
238-
>>> yield from r.text()
239-
{
240-
...
241-
"files": {
242-
"file": "<censored...binary...data>"
243-
},
244-
...
245-
}
237+
>>> yield from aiohttp.request('post', url, data=files)
246238

247239
You can set the filename, content_type explicitly::
248240

249241
>>> url = 'http://httpbin.org/post'
250-
>>> files = {'file': ('report.xls',
251-
... open('report.xls', 'rb'),
252-
... 'application/vnd.ms-excel')}
242+
>>> data = FormData()
243+
>>> data.add_field('report.xls',
244+
... open('report.xls', 'rb'),
245+
... content_type='application/vnd.ms-excel')
253246

254-
>>> r = aiohttp.request('post', url, data=files)
255-
>>> yield from r.text()
256-
{
257-
...
258-
"files": {
259-
"file": "<censored...binary...data>"
260-
},
261-
...
262-
}
247+
>>> yield from aiohttp.request('post', url, data=data)
263248

264249
If you want, you can send strings to be received as files::
265250

@@ -268,15 +253,7 @@ If you want, you can send strings to be received as files::
268253
... 'some,data,to,send\nanother,row,to,send\n')
269254
... }
270255

271-
>>> r = yield from aiohttp.request('post', url, data=files)
272-
>>> yield from r.text()
273-
{
274-
...
275-
"files": {
276-
"file": "some,data,to,send\\nanother,row,to,send\\n"
277-
},
278-
...
279-
}
256+
>>> yield from aiohttp.request('post', url, data=files)
280257

281258
If you pass file object as data parameter, aiohttp will stream it to server
282259
automatically. Check :class:`aiohttp.stream.StreamReader` for supported format

0 commit comments

Comments
 (0)