initialize
This commit is contained in:
23
backend/app/services/storage.py
Normal file
23
backend/app/services/storage.py
Normal file
@@ -0,0 +1,23 @@
|
||||
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
|
||||
Reference in New Issue
Block a user