add files router and update image URL path
This commit is contained in:
21
app/api/v1/files.py
Normal file
21
app/api/v1/files.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from starlette.responses import FileResponse
|
||||
|
||||
from app.api.v1.product.images import PRODUCTS_FOLDER
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/files",
|
||||
tags=["Files"]
|
||||
)
|
||||
|
||||
|
||||
@router.get('/images/{file_name}', response_class=FileResponse)
|
||||
async def get_image(file_name: str):
|
||||
products_folder = PRODUCTS_FOLDER
|
||||
file_path = os.path.join(products_folder, file_name)
|
||||
if not os.path.exists(file_path):
|
||||
raise HTTPException(status_code=404, detail="File not found")
|
||||
|
||||
return FileResponse(file_path)
|
||||
Reference in New Issue
Block a user