Streaming upload #6820
-
Is it possible on an aiohttp server to send an uploaded file to another server without loading it into memory? How can I do that? async def forward_huge_upload_to_upstream(request):
reader = await request.multipart()
field = await reader.next()
filename = field.filename
data = FormData()
data.add_field('data', ???, filename=field.filename, content_type=field.headers['Conent-Type'])
async with aiohttp.ClientSession() as session:
async with session.post(url, data=data) as response:
return web.Response(status=response.status, body=await response.text()) I found this, read a lot of documentation, but didn't understand how to use it. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The examples in this documentation section https://docs.aiohttp.org/en/stable/client_quickstart.html#streaming-uploads show how to pass a separate async generator function or a pre-opened file handle as a |
Beta Was this translation helpful? Give feedback.
The examples in this documentation section https://docs.aiohttp.org/en/stable/client_quickstart.html#streaming-uploads show how to pass a separate async generator function or a pre-opened file handle as a
data
. It also mentions that you should be able to just pass the incomingrequest.content
there. https://docs.aiohttp.org/en/stable/client_reference.html#aiohttp.ClientResponse.content seems to implement the async iterator protocol for this to work.