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
+1
View File
@@ -17,6 +17,7 @@ dependencies = [
"firebase-admin>=7.1.0",
"aioboto3==15.5.0",
"prometheus-fastapi-instrumentator>=7.1.0",
"python-multipart>=0.0.20",
]
[dependency-groups]
+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},
)
Generated
+12 -1
View File
@@ -1,5 +1,5 @@
version = 1
revision = 2
revision = 3
requires-python = ">=3.12"
resolution-markers = [
"python_full_version >= '3.14'",
@@ -1735,6 +1735,15 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/ec/57/56b9bcc3c9c6a792fcbaf139543cee77261f3651ca9da0c93f5c1221264b/python_dateutil-2.9.0.post0-py2.py3-none-any.whl", hash = "sha256:a8b2bc7bffae282281c8140a97d3aa9c14da0b136dfe83f850eea9a5f7470427", size = 229892, upload-time = "2024-03-01T18:36:18.57Z" },
]
[[package]]
name = "python-multipart"
version = "0.0.20"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/f3/87/f44d7c9f274c7ee665a29b885ec97089ec5dc034c7f3fafa03da9e39a09e/python_multipart-0.0.20.tar.gz", hash = "sha256:8dd0cab45b8e23064ae09147625994d090fa46f5b0d1e13af944c331a7fa9d13", size = 37158, upload-time = "2024-12-16T19:45:46.972Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/45/58/38b5afbc1a800eeea951b9285d3912613f2603bdf897a4ab0f4bd7f405fc/python_multipart-0.0.20-py3-none-any.whl", hash = "sha256:8a62d3a8335e06589fe01f2a3e178cdcc632f3fbe0d492ad9ee0ec35aab1f104", size = 24546, upload-time = "2024-12-16T19:45:44.423Z" },
]
[[package]]
name = "pyyaml"
version = "6.0.3"
@@ -1943,6 +1952,7 @@ dependencies = [
{ name = "httpx" },
{ name = "prometheus-fastapi-instrumentator" },
{ name = "psycopg", extra = ["binary"] },
{ name = "python-multipart" },
{ name = "sqlalchemy" },
{ name = "uuid-utils" },
{ name = "uvicorn" },
@@ -1991,6 +2001,7 @@ requires-dist = [
{ name = "httpx", specifier = "==0.28.1" },
{ name = "prometheus-fastapi-instrumentator", specifier = ">=7.1.0" },
{ name = "psycopg", extras = ["binary"], specifier = ">=3.2.12" },
{ name = "python-multipart", specifier = ">=0.0.20" },
{ name = "sqlalchemy", specifier = "==2.0.44" },
{ name = "uuid-utils", specifier = "==0.11.1" },
{ name = "uvicorn", specifier = "==0.37.0" },