Skip to content

Instantly share code, notes, and snippets.

Created Feb 27, 2017
What would you like to do?
Streaming s3 file for downloads
# using aiobotocore and plone.server(aiohttp)
ob = await client.get_object(Bucket=bucket, Key=key)
info = ob['ResponseMetadata']['HTTPHeaders']
resp = aiohttp.web.StreamResponse(headers=aiohttp.MultiDict({
'CONTENT-DISPOSITION': 'attachment; filename="%s"' % self.filename,
'Content-Type': info['content-type']
resp.content_type = info['content-type']
resp.content_length = info['content-length']
await resp.prepare(self.request)
async with ob['Body'] as stream:
file_data = await
while file_data:
file_data = await
return resp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment