22 lines
584 B
Python
22 lines
584 B
Python
import os
|
|
from fastapi import APIRouter, HTTPException
|
|
from starlette.responses import FileResponse
|
|
|
|
from app.config.config_reader import images_url
|
|
|
|
view = APIRouter()
|
|
|
|
|
|
@view.get("/{file_path:path}")
|
|
def view_img(file_path):
|
|
"""
|
|
查看图片
|
|
:param file_path: 图片路径
|
|
:return:
|
|
"""
|
|
image_path = os.path.join(images_url, file_path)
|
|
# 检查文件是否存在以及是否是文件
|
|
if not os.path.isfile(image_path):
|
|
raise HTTPException(status_code=404, detail="Image not found")
|
|
return FileResponse(image_path, media_type='image/jpeg')
|