first commit
This commit is contained in:
20
backend/services/file_utils.py
Normal file
20
backend/services/file_utils.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi import UploadFile
|
||||
|
||||
from backend.config import settings
|
||||
|
||||
|
||||
def ensure_upload_dir() -> Path:
|
||||
target = Path(settings.upload_dir)
|
||||
target.mkdir(parents=True, exist_ok=True)
|
||||
return target
|
||||
|
||||
|
||||
def save_upload(upload_file: UploadFile) -> Path:
|
||||
target_dir = ensure_upload_dir()
|
||||
target_path = target_dir / upload_file.filename
|
||||
with target_path.open("wb") as buffer:
|
||||
shutil.copyfileobj(upload_file.file, buffer)
|
||||
return target_path
|
||||
Reference in New Issue
Block a user