19 lines
569 B
Python
19 lines
569 B
Python
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
|