first commit
This commit is contained in:
18
backend/app/utils/file_storage.py
Normal file
18
backend/app/utils/file_storage.py
Normal file
@@ -0,0 +1,18 @@
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
from app.core.config import settings
|
||||
|
||||
|
||||
def save_upload(data: bytes, case_id: str, filename: str) -> tuple[str, str]:
|
||||
"""Save uploaded file and return (file_path, thumb_path) relative to UPLOAD_DIR."""
|
||||
case_dir = settings.upload_path / case_id
|
||||
case_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
ext = Path(filename).suffix or ".png"
|
||||
unique_name = f"{uuid.uuid4().hex}{ext}"
|
||||
file_path = case_dir / unique_name
|
||||
file_path.write_bytes(data)
|
||||
|
||||
relative = f"{case_id}/{unique_name}"
|
||||
return relative, relative
|
||||
Reference in New Issue
Block a user