Files
Karlcarlo 409dabafb5 feat: 初始化孕育无忧全栈项目基础代码结构
完成项目初始搭建,包含后端FastAPI+MongoDB服务、前端React+Vite项目的完整基础结构,添加各类配置文件与依赖清单,涵盖核心业务初始框架。
2026-05-21 00:46:48 +08:00

25 lines
685 B
Python

import os
import uuid
from pathlib import Path
import aiofiles
from fastapi import UploadFile
from app.config import settings
async def save_upload_file(file: UploadFile, sub_dir: str = "reports") -> str:
"""Save uploaded file and return the relative URL path"""
upload_path = Path(settings.upload_dir) / sub_dir
upload_path.mkdir(parents=True, exist_ok=True)
ext = Path(file.filename).suffix if file.filename else ".jpg"
filename = f"{uuid.uuid4().hex}{ext}"
file_path = upload_path / filename
content = await file.read()
async with aiofiles.open(file_path, "wb") as f:
await f.write(content)
return f"/uploads/{sub_dir}/{filename}"