From faf9bda77adf5dd1c32f4aec6f62dec3af45ee47 Mon Sep 17 00:00:00 2001 From: Hyungi Ahn Date: Fri, 3 Apr 2026 08:38:10 +0900 Subject: [PATCH] fix: set correct Content-Type and inline disposition for file serving PDF was downloading instead of displaying because media_type was None (defaulting to octet-stream). Now maps file extensions to proper MIME types and sets Content-Disposition: inline for in-browser viewing. Co-Authored-By: Claude Opus 4.6 (1M context) --- app/api/documents.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/app/api/documents.py b/app/api/documents.py index a11ce58..d6462c0 100644 --- a/app/api/documents.py +++ b/app/api/documents.py @@ -188,10 +188,24 @@ async def get_document_file( if not file_path.exists(): raise HTTPException(status_code=404, detail="파일을 찾을 수 없습니다") + # 미디어 타입 매핑 + media_types = { + ".pdf": "application/pdf", + ".jpg": "image/jpeg", ".jpeg": "image/jpeg", + ".png": "image/png", ".gif": "image/gif", + ".bmp": "image/bmp", ".tiff": "image/tiff", + ".svg": "image/svg+xml", + ".txt": "text/plain", ".md": "text/plain", + ".html": "text/html", ".csv": "text/csv", + ".json": "application/json", ".xml": "application/xml", + } + suffix = file_path.suffix.lower() + media_type = media_types.get(suffix, "application/octet-stream") + return FileResponse( path=str(file_path), - filename=file_path.name, - media_type=None, + media_type=media_type, + headers={"Content-Disposition": "inline"}, )