24 lines
559 B
Python
24 lines
559 B
Python
import shutil
|
|
import uuid
|
|
from pathlib import Path
|
|
from typing import Tuple
|
|
|
|
from fastapi import UploadFile
|
|
|
|
from app.config import UPLOAD_DIR
|
|
|
|
|
|
def save_upload(file: UploadFile) -> Tuple[str, str]:
|
|
suffix = Path(file.filename or "").suffix.lower() or ".mp4"
|
|
file_id = f"{uuid.uuid4().hex}{suffix}"
|
|
destination = UPLOAD_DIR / file_id
|
|
|
|
with destination.open("wb") as buffer:
|
|
shutil.copyfileobj(file.file, buffer)
|
|
|
|
return file_id, file.filename or file_id
|
|
|
|
|
|
def get_upload_path(file_id: str) -> Path:
|
|
return UPLOAD_DIR / file_id
|