feat(): storage upload file route

This commit is contained in:
gitgernit
2025-11-21 12:11:40 +03:00
parent fb6c415f1e
commit ef4f2ec999
4 changed files with 43 additions and 2 deletions
+2 -1
View File
@@ -19,7 +19,7 @@ from prometheus_fastapi_instrumentator import Instrumentator
from template_project.web_api.configuration import Configuration, load_configuration
from template_project.web_api.ioc.make import make_ioc
from template_project.web_api.routes import auth, healthcheck, notification, profile
from template_project.web_api.routes import auth, healthcheck, notification, profile, storage
LOG_CONFIG: Final = {
"version": 1,
@@ -73,6 +73,7 @@ def make_asgi_application(
app.include_router(healthcheck.router)
app.include_router(profile.router)
app.include_router(notification.router)
app.include_router(storage.router)
Instrumentator().instrument(app).expose(app)
setup_dishka(container=ioc, app=app)
@@ -0,0 +1,28 @@
from io import BytesIO
from dishka import FromDishka
from dishka.integrations.fastapi import DishkaRoute
from fastapi import APIRouter, Depends, UploadFile, status
from fastapi.responses import JSONResponse
from fastapi.security import HTTPBearer
from uuid_utils.compat import uuid7
from template_project.application.common.file_storage import FileStorage
security = HTTPBearer()
router = APIRouter(route_class=DishkaRoute, tags=["Storage"], dependencies=[Depends(security)])
@router.post("/storage/upload_file")
async def upload_file(
file: UploadFile,
file_storage: FromDishka[FileStorage],
) -> JSONResponse:
path = str(uuid7())
file_content = await file.read()
file_io = BytesIO(file_content)
await file_storage.upload(path=path, image=file_io)
return JSONResponse(
status_code=status.HTTP_200_OK,
content={"path": path},
)