@@ -234,32 +234,17 @@ To upload Multipart-encoded files::
234
234
>>> url = 'http://httpbin.org/post'
235
235
>>> files = {'file': open('report.xls', 'rb')}
236
236
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)
246
238
247
239
You can set the filename, content_type explicitly::
248
240
249
241
>>> 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')
253
246
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)
263
248
264
249
If you want, you can send strings to be received as files::
265
250
@@ -268,15 +253,7 @@ If you want, you can send strings to be received as files::
268
253
... 'some,data,to,send\nanother,row,to,send\n')
269
254
... }
270
255
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)
280
257
281
258
If you pass file object as data parameter, aiohttp will stream it to server
282
259
automatically. Check :class: `aiohttp.stream.StreamReader ` for supported format
0 commit comments