From f7c3530102283623f7d0fff7ff598da39cf3269d Mon Sep 17 00:00:00 2001 From: Christian Barra Date: Thu, 26 Oct 2017 20:03:09 +0200 Subject: [PATCH 1/2] Small improvement docs: better example for file uploads. --- docs/web.rst | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/docs/web.rst b/docs/web.rst index a66d9f3c42f..bc23ececfac 100644 --- a/docs/web.rst +++ b/docs/web.rst @@ -743,15 +743,20 @@ should use :meth:`Request.multipart` which returns a :ref:`multipart reader # /!\ Don't forget to validate your inputs /!\ - mp3 = await reader.next() + # reader.next() will `yield` the fields of your form - filename = mp3.filename + field = await reader.next() + assert field.name == 'name' + name = await field.read(decode=True) + field = await reader.next() + assert field.name == 'mp3' + filename = field.filename # You cannot rely on Content-Length if transfer is chunked. size = 0 with open(os.path.join('/spool/yarrr-media/mp3/', filename), 'wb') as f: while True: - chunk = await mp3.read_chunk() # 8192 bytes by default. + chunk = await field.read_chunk() # 8192 bytes by default. if not chunk: break size += len(chunk) @@ -789,10 +794,10 @@ with the peer:: print('websocket connection closed') return ws - -The handler should be registered as HTTP GET processor:: - - app.router.add_get('/ws', websocket_handler) + +The handler should be registered as HTTP GET processor:: + + app.router.add_get('/ws', websocket_handler) .. _aiohttp-web-websocket-read-same-task: From ba3b594e36e9dd187be841bf5b4c3c1b4f67d6fc Mon Sep 17 00:00:00 2001 From: Christian Barra Date: Thu, 26 Oct 2017 20:07:31 +0200 Subject: [PATCH 2/2] Add fragment 2401.doc to CHANGES --- CHANGES/2401.doc | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/2401.doc diff --git a/CHANGES/2401.doc b/CHANGES/2401.doc new file mode 100644 index 00000000000..feb70aeeab4 --- /dev/null +++ b/CHANGES/2401.doc @@ -0,0 +1 @@ +Small improvement docs: better example for file uploads. \ No newline at end of file