From 6e2d519c4434736b324d5e3b06e95d7198a58965 Mon Sep 17 00:00:00 2001 From: Sam Warner Date: Tue, 4 Feb 2025 11:35:24 +1100 Subject: [PATCH] fix chat image upload double read --- backend/onyx/server/query_and_chat/chat_backend.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/backend/onyx/server/query_and_chat/chat_backend.py b/backend/onyx/server/query_and_chat/chat_backend.py index f671ccfedf21..2aba347a513d 100644 --- a/backend/onyx/server/query_and_chat/chat_backend.py +++ b/backend/onyx/server/query_and_chat/chat_backend.py @@ -672,8 +672,6 @@ def upload_files_for_chat( else ChatFileType.PLAIN_TEXT ) - file_content = file.file.read() # Read the file content - if file_type == ChatFileType.IMAGE: file_content_io = file.file # NOTE: Image conversion to JPEG used to be enforced here. @@ -682,7 +680,7 @@ def upload_files_for_chat( # 2. Maintain transparency in formats like PNG # 3. Ameliorate issue with file conversion else: - file_content_io = io.BytesIO(file_content) + file_content_io = io.BytesIO(file.file.read()) new_content_type = file.content_type @@ -700,7 +698,7 @@ def upload_files_for_chat( # to re-extract it every time we send a message if file_type == ChatFileType.DOC: extracted_text = extract_file_text( - file=io.BytesIO(file_content), # use the bytes we already read + file=file_content_io, # use the bytes we already read file_name=file.filename or "", ) text_file_id = str(uuid.uuid4())