payload_streamer

Payload implemenation for coroutines as data provider.

As a simple case, you can upload data from file:

@aiohttp.streamer
async def file_sender(writer, file_name=None):
   with open(file_name, 'rb') as f:
       chunk = f.read(2**16)
       while chunk:
           await writer.write(chunk)

           chunk = f.read(2**16)

Then you can use file_sender like this:

async with session.post(‘http://httpbin.org/post’,
data=file_sender(file_name=’huge_file’)) as resp:

print(await resp.text())

..note:: Coroutine must accept writer as first argument

Module Contents

Classes

_stream_wrapper(self,coro,args,kwargs)
streamer(self,coro)
StreamWrapperPayload()
StreamPayload(self,value,*args,**kwargs)
class _stream_wrapper(coro, args, kwargs)
__init__(coro, args, kwargs)
__call__(writer)
class streamer(coro)
__init__(coro)
__call__(*args, **kwargs)
class StreamWrapperPayload
write(writer)
class StreamPayload(value, *args, **kwargs)
__init__(value, *args, **kwargs)
write(writer)