[Bugfix] Emit a valid media type from encode_{audio,image,video}_url (#49056)

Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
This commit is contained in:
Vineeth Sai Varikuntla
2026-08-03 19:02:23 +00:00
committed by GitHub
parent 8f50685c48
commit 7f2e78ba4d
2 changed files with 21 additions and 4 deletions
+5 -3
View File
@@ -57,7 +57,7 @@ def encode_audio_url(
) -> str:
"""Encode audio as a data URL."""
audio_b64 = encode_audio_base64(audio, sampling_rate, format=format)
mimetype = mimetypes.types_map.get("." + format.lower(), "audio")
mimetype = mimetypes.types_map.get("." + format.lower(), f"audio/{format.lower()}")
return f"data:{mimetype};base64,{audio_b64}"
@@ -90,7 +90,7 @@ def encode_image_url(
Pass `image_mode=None` to keep the original image mode.
"""
image_b64 = encode_image_base64(image, image_mode=image_mode, format=format)
mimetype = mimetypes.types_map.get("." + format.lower(), "image")
mimetype = mimetypes.types_map.get("." + format.lower(), f"image/{format.lower()}")
return f"data:{mimetype};base64,{image_b64}"
@@ -114,7 +114,9 @@ def encode_video_url(
if format.lower() == "jpeg":
mimetype = "video/jpeg"
else:
mimetype = mimetypes.types_map.get("." + format.lower(), "video")
mimetype = mimetypes.types_map.get(
"." + format.lower(), f"video/{format.lower()}"
)
return f"data:{mimetype};base64,{video_b64}"