fix: extract correct MIME type from base64 profile images (#20171)
This commit is contained in:
@@ -306,12 +306,13 @@ async def get_model_profile_image(id: str, user=Depends(get_verified_user)):
|
|||||||
header, base64_data = model.meta.profile_image_url.split(",", 1)
|
header, base64_data = model.meta.profile_image_url.split(",", 1)
|
||||||
image_data = base64.b64decode(base64_data)
|
image_data = base64.b64decode(base64_data)
|
||||||
image_buffer = io.BytesIO(image_data)
|
image_buffer = io.BytesIO(image_data)
|
||||||
|
media_type = header.split(";")[0].lstrip("data:")
|
||||||
|
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
image_buffer,
|
image_buffer,
|
||||||
media_type="image/png",
|
media_type=media_type,
|
||||||
headers={
|
headers={
|
||||||
"Content-Disposition": "inline; filename=image.png",
|
"Content-Disposition": "inline",
|
||||||
**cache_headers,
|
**cache_headers,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -461,11 +461,12 @@ async def get_user_profile_image_by_id(user_id: str, user=Depends(get_verified_u
|
|||||||
header, base64_data = user.profile_image_url.split(",", 1)
|
header, base64_data = user.profile_image_url.split(",", 1)
|
||||||
image_data = base64.b64decode(base64_data)
|
image_data = base64.b64decode(base64_data)
|
||||||
image_buffer = io.BytesIO(image_data)
|
image_buffer = io.BytesIO(image_data)
|
||||||
|
media_type = header.split(";")[0].lstrip("data:")
|
||||||
|
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
image_buffer,
|
image_buffer,
|
||||||
media_type="image/png",
|
media_type=media_type,
|
||||||
headers={"Content-Disposition": "inline; filename=image.png"},
|
headers={"Content-Disposition": "inline"},
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user