feat: 初始化孕育无忧全栈项目基础代码结构
完成项目初始搭建,包含后端FastAPI+MongoDB服务、前端React+Vite项目的完整基础结构,添加各类配置文件与依赖清单,涵盖核心业务初始框架。
This commit is contained in:
24
backend/app/services/storage.py
Normal file
24
backend/app/services/storage.py
Normal file
@@ -0,0 +1,24 @@
|
||||
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}"
|
||||
Reference in New Issue
Block a user