Skip to content

Instantly share code, notes, and snippets.

@RomanAVolodin
Last active February 27, 2024 11:37
Show Gist options
  • Save RomanAVolodin/d4e79f32ed7da1ea368593269ef86713 to your computer and use it in GitHub Desktop.
Save RomanAVolodin/d4e79f32ed7da1ea368593269ef86713 to your computer and use it in GitHub Desktop.
async def get_file_by_short_name(self, short_name: shortuuid) -> StreamingResponse:
file = await self.__repository.get_by_short_name(short_name=short_name)
async def s3_stream():
async with aiohttp.ClientSession() as session:
result = await self.__storage.get_object_response_by_path(
session=session, bucket=settings.bucket_name, path=file.path_in_storage
)
async for chunk in result.content.iter_chunked(32 * 1024):
yield chunk
filename = file.filename.encode('utf-8')
return StreamingResponse(
content=s3_stream(), media_type=file.file_type, headers={'Content-Disposition': f'filename="{filename}"'}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment