17 lines
715 B
Python
17 lines
715 B
Python
# app/api/v1/upload.py
|
|
from fastapi import APIRouter, Depends, UploadFile, File, HTTPException
|
|
from fastapi.security import OAuth2PasswordBearer
|
|
from config.database import get_db
|
|
from services.auth_service import AuthService
|
|
from services.upload_service import UploadService
|
|
from utils.logging import logger
|
|
|
|
router = APIRouter()
|
|
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/v1/auth/token")
|
|
|
|
@router.post("/")
|
|
async def upload_file(file: UploadFile, token: str = Depends(oauth2_scheme)):
|
|
async with get_db() as db:
|
|
user = await AuthService.get_current_user(token, db)
|
|
logger.info(f"User {user} is uploading a file")
|
|
return await UploadService.upload_image_to_s3(file, user["id"]) |