Skip to content

Commit 09335d2

Browse files
committed
fix(openwebui): use HTMLResponse with Content-Disposition inline
OpenWebUI displays text/html responses with Content-Disposition: inline as iframe embeds. This should properly display the generated image.
1 parent a34ca77 commit 09335d2

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

app/api/routes/edit.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from typing import Annotated, Literal
66

77
from fastapi import APIRouter, Depends, File, Form, HTTPException, UploadFile
8+
from fastapi.responses import HTMLResponse
89

910
from app.core.config import settings
1011
from app.core.security import verify_token
@@ -219,7 +220,7 @@ async def edit_image_json(
219220
if not urls:
220221
raise HTTPException(status_code=500, detail="No images generated")
221222

222-
# OpenWebUI mode: return markdown with embedded base64 image
223+
# OpenWebUI mode: return HTML with embedded image for iframe display
223224
if settings.OPENWEBUI_MODE:
224225
image_filename = urls[0].split("/")[-1]
225226
image_path = Path(settings.STORAGE_PATH) / image_filename
@@ -239,7 +240,8 @@ async def edit_image_json(
239240
mime_types = {".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp"}
240241
mime_type = mime_types.get(ext, "image/png")
241242

242-
return f"![Edited Image](data:{mime_type};base64,{image_data})"
243+
html = f'<img src="data:{mime_type};base64,{image_data}" style="max-width:100%; height:auto;">'
244+
return HTMLResponse(content=html, headers={"Content-Disposition": "inline"})
243245

244246
# Return based on MARKDOWN_EMBED_IMAGES setting
245247
if settings.MARKDOWN_EMBED_IMAGES:

app/api/routes/generate.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def generate_image(request: ImageRequest, _: None = Depends(verify_token))
7070
if not urls:
7171
raise HTTPException(status_code=500, detail="No images generated")
7272

73-
# OpenWebUI mode: return markdown with embedded base64 image
73+
# OpenWebUI mode: return HTML with embedded image for iframe display
7474
if settings.OPENWEBUI_MODE:
7575
image_filename = urls[0].split("/")[-1]
7676
image_path = Path(settings.STORAGE_PATH) / image_filename
@@ -90,7 +90,8 @@ async def generate_image(request: ImageRequest, _: None = Depends(verify_token))
9090
mime_types = {".png": "image/png", ".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".webp": "image/webp"}
9191
mime_type = mime_types.get(ext, "image/png")
9292

93-
return f"![Generated Image](data:{mime_type};base64,{image_data})"
93+
html = f'<img src="data:{mime_type};base64,{image_data}" style="max-width:100%; height:auto;">'
94+
return HTMLResponse(content=html, headers={"Content-Disposition": "inline"})
9495

9596
# Handle response format
9697
if request.response_format == "base64":

0 commit comments

Comments
 (0)