Last active
February 27, 2024 11:37
-
-
Save RomanAVolodin/d4e79f32ed7da1ea368593269ef86713 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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