From eaab14ae573156ffe017f0a872530a054516408f Mon Sep 17 00:00:00 2001 From: bsiggel Date: Sat, 14 Mar 2026 23:00:49 +0000 Subject: [PATCH] fix: Adjust multipart form to use raw UTF-8 encoding for filenames in file uploads --- services/xai_service.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/services/xai_service.py b/services/xai_service.py index eca4758..fb219d8 100644 --- a/services/xai_service.py +++ b/services/xai_service.py @@ -69,8 +69,16 @@ class XAIService: url = f"{XAI_FILES_URL}/v1/files" headers = {"Authorization": f"Bearer {self.api_key}"} - form = aiohttp.FormData() - form.add_field('file', file_content, filename=filename, content_type=mime_type) + # Create multipart form with explicit UTF-8 filename encoding + # aiohttp automatically URL-encodes filenames with special chars, + # but xAI expects raw UTF-8 in the filename parameter + form = aiohttp.FormData(quote_fields=False) + form.add_field( + 'file', + file_content, + filename=filename, + content_type=mime_type + ) async with session.post(url, data=form, headers=headers) as response: try: