rkuo-danswer 24184024bb
Bugfix/dependency updates (#4482)
* bump fastapi and starlette

* bumping llama index and nltk and associated deps

* bump to fix python-multipart

* bump aiohttp

* update package lock for examples/widget

* bump black

* sentencesplitter has changed namespaces

* fix reorder import check, fix missing passlib

* update package-lock.json

* black formatter updated

* reformatted again

* change to black compatible reorder

* change to black compatible reorder-python-imports fork

* fix pytest dependency

* black format again

* we don't need cdk.txt. update packages to be consistent across all packages

---------

Co-authored-by: Richard Kuo (Onyx) <rkuo@onyx.app>
Co-authored-by: Richard Kuo <rkuo@rkuo.com>
2025-04-10 08:23:02 +00:00

26 lines
764 B
Python

import base64
def get_image_type_from_bytes(raw_b64_bytes: bytes) -> str:
magic_number = raw_b64_bytes[:4]
if magic_number.startswith(b"\x89PNG"):
mime_type = "image/png"
elif magic_number.startswith(b"\xff\xd8"):
mime_type = "image/jpeg"
elif magic_number.startswith(b"GIF8"):
mime_type = "image/gif"
elif magic_number.startswith(b"RIFF") and raw_b64_bytes[8:12] == b"WEBP":
mime_type = "image/webp"
else:
raise ValueError(
"Unsupported image format - only PNG, JPEG, " "GIF, and WEBP are supported."
)
return mime_type
def get_image_type(raw_b64_string: str) -> str:
binary_data = base64.b64decode(raw_b64_string)
return get_image_type_from_bytes(binary_data)