|
4 | 4 | author_url: https://github.com/owndev/ |
5 | 5 | project_url: https://github.com/owndev/Open-WebUI-Functions |
6 | 6 | funding_url: https://github.com/sponsors/owndev |
7 | | -version: 1.9.1 |
| 7 | +version: 1.9.2 |
8 | 8 | required_open_webui_version: 0.6.26 |
9 | 9 | license: Apache License 2.0 |
10 | 10 | description: Highly optimized Google Gemini pipeline with advanced image generation capabilities, intelligent compression, and streamlined processing workflows. |
@@ -1359,15 +1359,20 @@ async def _fetch_file_as_base64(self, file_url: str) -> Optional[str]: |
1359 | 1359 | else: |
1360 | 1360 | fid = file_url.split("/files/")[-1].split("/")[0].split("?")[0] |
1361 | 1361 |
|
| 1362 | + from pathlib import Path |
1362 | 1363 | from open_webui.models.files import Files |
| 1364 | + from open_webui.storage.provider import Storage |
1363 | 1365 |
|
1364 | 1366 | file_obj = Files.get_file_by_id(fid) |
1365 | 1367 | if file_obj and file_obj.path: |
1366 | | - async with aiofiles.open(file_obj.path, "rb") as fp: |
1367 | | - raw = await fp.read() |
1368 | | - enc = base64.b64encode(raw).decode() |
1369 | | - mime = file_obj.meta.get("content_type", "image/png") |
1370 | | - return f"data:{mime};base64,{enc}" |
| 1368 | + file_path = Storage.get_file(file_obj.path) |
| 1369 | + file_path = Path(file_path) |
| 1370 | + if file_path.is_file(): |
| 1371 | + async with aiofiles.open(file_path, "rb") as fp: |
| 1372 | + raw = await fp.read() |
| 1373 | + enc = base64.b64encode(raw).decode() |
| 1374 | + mime = file_obj.meta.get("content_type", "image/png") |
| 1375 | + return f"data:{mime};base64,{enc}" |
1371 | 1376 | except Exception as e: |
1372 | 1377 | self.log.warning(f"Could not fetch file {file_url}: {e}") |
1373 | 1378 | return None |
|
0 commit comments