项目基础模块代码
This commit is contained in:
21
app/api/common/view_img.py
Normal file
21
app/api/common/view_img.py
Normal file
@ -0,0 +1,21 @@
|
||||
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')
|
Reference in New Issue
Block a user