add endpoint to download profile picture

This commit is contained in:
italojohnny 2024-06-07 18:46:18 -03:00
commit 08a259da86

View file

@ -100,6 +100,25 @@ async def download_image(file_name: str, flow_id: UUID, storage_service: Storage
raise HTTPException(status_code=500, detail=str(e))
@router.get("/profile_pictures/{folder_name}/{file_name}")
async def download_profile_picture(
folder_name: str,
file_name: str,
storage_service: StorageService = Depends(get_storage_service),
):
try:
extension = file_name.split(".")[-1]
config_dir = get_storage_service().settings_service.settings.config_dir
config_path = Path(config_dir)
folder_path = config_path / 'profile_pictures' / folder_name
content_type = build_content_type_from_extension(extension)
file_content = await storage_service.get_file(flow_id=folder_path, file_name=file_name)
return StreamingResponse(BytesIO(file_content), media_type=content_type)
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@router.get("/profile_pictures/list")
async def list_profile_pictures(storage_service: StorageService = Depends(get_storage_service)):
try: