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) <noreply@anthropic.com>
This commit is contained in:
@@ -188,10 +188,24 @@ async def get_document_file(
|
|||||||
if not file_path.exists():
|
if not file_path.exists():
|
||||||
raise HTTPException(status_code=404, detail="파일을 찾을 수 없습니다")
|
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(
|
return FileResponse(
|
||||||
path=str(file_path),
|
path=str(file_path),
|
||||||
filename=file_path.name,
|
media_type=media_type,
|
||||||
media_type=None,
|
headers={"Content-Disposition": "inline"},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user