diff --git a/backend/open_webui/routers/channels.py b/backend/open_webui/routers/channels.py index 91731c920c..62388bd3e9 100644 --- a/backend/open_webui/routers/channels.py +++ b/backend/open_webui/routers/channels.py @@ -1,12 +1,11 @@ import base64 -import io import logging import time import uuid from typing import Optional from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException, Request, status -from fastapi.responses import FileResponse, Response, StreamingResponse +from fastapi.responses import FileResponse, Response from open_webui.config import ENABLE_ADMIN_CHAT_ACCESS, ENABLE_ADMIN_EXPORT from open_webui.constants import ERROR_MESSAGES from open_webui.env import ENABLE_PROFILE_IMAGE_URL_FORWARDING, STATIC_DIR @@ -2099,11 +2098,10 @@ async def get_webhook_profile_image( try: header, base64_data = webhook.profile_image_url.split(',', 1) image_data = base64.b64decode(base64_data) - image_buffer = io.BytesIO(image_data) media_type = header.split(';')[0].lstrip('data:') - return StreamingResponse( - image_buffer, + return Response( + content=image_data, media_type=media_type, headers={'Content-Disposition': 'inline'}, ) diff --git a/backend/open_webui/routers/knowledge.py b/backend/open_webui/routers/knowledge.py index 2c57490b83..fde3a282df 100644 --- a/backend/open_webui/routers/knowledge.py +++ b/backend/open_webui/routers/knowledge.py @@ -10,7 +10,7 @@ from typing import List, Optional from urllib.parse import quote from fastapi import APIRouter, Depends, HTTPException, Query, Request, status -from fastapi.responses import StreamingResponse +from fastapi.responses import Response, StreamingResponse from open_webui.config import ( BYPASS_ADMIN_ACCESS_CONTROL, ENABLE_KNOWLEDGE_FILE_RETENTION, @@ -2311,14 +2311,12 @@ async def export_knowledge_by_id(id: str, user=Depends(get_admin_user), db: Asyn filename = f'{filename}.txt' zf.writestr(filename, content) - zip_buffer.seek(0) - # Sanitize knowledge name for filename safe_name = ''.join(c if c.isalnum() or c in ' -_' else '_' for c in knowledge.name) zip_filename = f'{safe_name}.zip' - return StreamingResponse( - zip_buffer, + return Response( + content=zip_buffer.getvalue(), media_type='application/zip', headers={'Content-Disposition': f"attachment; filename*=UTF-8''{quote(zip_filename, safe='')}"}, ) diff --git a/backend/open_webui/routers/models.py b/backend/open_webui/routers/models.py index 918700b290..2ce450eab2 100644 --- a/backend/open_webui/routers/models.py +++ b/backend/open_webui/routers/models.py @@ -18,7 +18,7 @@ from fastapi import ( Response, status, ) -from fastapi.responses import RedirectResponse, StreamingResponse +from fastapi.responses import RedirectResponse from open_webui.config import BYPASS_ADMIN_ACCESS_CONTROL from open_webui.constants import ERROR_MESSAGES from open_webui.env import ( @@ -1020,7 +1020,6 @@ async def get_model_profile_image( try: header, base64_data = profile_image_url.split(',', 1) image_data = base64.b64decode(base64_data) - image_buffer = io.BytesIO(image_data) media_type = header.split(';')[0].lstrip('data:').lower() # only serve known-safe raster types inline; reject SVG/unknown (can run script on our origin) @@ -1040,8 +1039,8 @@ async def get_model_profile_image( if updated_at: headers['ETag'] = f'"{updated_at}"' - return StreamingResponse( - image_buffer, + return Response( + content=image_data, media_type=media_type, headers=headers, ) diff --git a/backend/open_webui/routers/users.py b/backend/open_webui/routers/users.py index 3d33d56e71..74516d0e2c 100644 --- a/backend/open_webui/routers/users.py +++ b/backend/open_webui/routers/users.py @@ -1,7 +1,6 @@ from __future__ import annotations import base64 -import io import logging import time from collections import Counter @@ -10,7 +9,7 @@ from datetime import datetime, timedelta from typing import Optional from fastapi import APIRouter, Depends, HTTPException, Query, Request, status -from fastapi.responses import FileResponse, Response, StreamingResponse +from fastapi.responses import FileResponse, Response from open_webui.config import DEFAULT_USER_PERMISSIONS from open_webui.constants import ERROR_MESSAGES from open_webui.events import EVENTS, publish_event @@ -850,14 +849,13 @@ async def get_user_profile_image_by_id(user_id: str, user=Depends(get_verified_u try: header, base64_data = user.profile_image_url.split(',', 1) image_data = base64.b64decode(base64_data) - image_buffer = io.BytesIO(image_data) media_type = header.split(';')[0].lstrip('data:').lower() if media_type not in PROFILE_IMAGE_ALLOWED_MIME_TYPES: return FileResponse(f'{STATIC_DIR}/user.png') - return StreamingResponse( - image_buffer, + return Response( + content=image_data, media_type=media_type, headers={ 'Content-Disposition': 'inline',