Skip to content

Commit 4cbb0e7

Browse files
fix: fix the incorrect file retrieval method to obtain files from S3
Refactor file reading logic to use Storage provider and pathlib for file path handling. Signed-off-by: Shirasawa <764798966@qq.com>
1 parent 7131114 commit 4cbb0e7

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

pipelines/google/google_gemini.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,15 +1358,20 @@ async def _fetch_file_as_base64(self, file_url: str) -> Optional[str]:
13581358
else:
13591359
fid = file_url.split("/files/")[-1].split("/")[0].split("?")[0]
13601360

1361+
from pathlib import Path
13611362
from open_webui.models.files import Files
1363+
from open_webui.storage.provider import Storage
13621364

13631365
file_obj = Files.get_file_by_id(fid)
13641366
if file_obj and file_obj.path:
1365-
async with aiofiles.open(file_obj.path, "rb") as fp:
1366-
raw = await fp.read()
1367-
enc = base64.b64encode(raw).decode()
1368-
mime = file_obj.meta.get("content_type", "image/png")
1369-
return f"data:{mime};base64,{enc}"
1367+
file_path = Storage.get_file(file_obj.path)
1368+
file_path = Path(file_path)
1369+
if file_path.is_file():
1370+
async with aiofiles.open(file_path, "rb") as fp:
1371+
raw = await fp.read()
1372+
enc = base64.b64encode(raw).decode()
1373+
mime = file_obj.meta.get("content_type", "image/png")
1374+
return f"data:{mime};base64,{enc}"
13701375
except Exception as e:
13711376
self.log.warning(f"Could not fetch file {file_url}: {e}")
13721377
return None

0 commit comments

Comments
 (0)