feat: offload all file i/o in server endpoints LET-6252 (#6300)

feat: offload all file i/o in server endpoints
This commit is contained in:
cthomas
2025-11-20 12:46:03 -08:00
committed by Caren Thomas
parent 4bb116f17c
commit 345ea42630
7 changed files with 71 additions and 39 deletions

View File

@@ -98,9 +98,12 @@ async def _convert_message_create_to_message(
parsed = urlparse(url)
file_path = unquote(parsed.path)
# Read file directly from filesystem
with open(file_path, "rb") as f:
image_bytes = f.read()
# Read file directly from filesystem (wrapped to avoid blocking event loop)
def _read_file():
with open(file_path, "rb") as f:
return f.read()
image_bytes = await asyncio.to_thread(_read_file)
# Guess media type from file extension
image_media_type, _ = mimetypes.guess_type(file_path)