from typing import Any from fastapi import APIRouter, Depends, UploadFile, File import os from app.dependencies import get_current_user router = APIRouter() @router.post("/user/upload") async def upload_file(file: UploadFile = File(...), current_user: Any = Depends(get_current_user)): upload_dir = "/home/user/data/uploads" # Ensure the upload directory exists os.makedirs(upload_dir, exist_ok=True) # This creates the directory if it doesn't exist, does nothing otherwise file_location = f"{upload_dir}/{file.filename}" with open(file_location, "wb") as buffer: contents = await file.read() buffer.write(contents) return { "status": "File uploaded successfully.", "user_id": current_user["user_id"], "name": current_user["name"], "role": current_user["role"] }