Skip to content

Instantly share code, notes, and snippets.

@vangheem
Created Feb 27, 2017
Embed
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)
resp.start(self.request)
async with ob['Body'] as stream:
file_data = await stream.read(self.chunk_size)
while file_data:
resp.write(file_data)
file_data = await stream.read(self.chunk_size)
return resp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment