File size: 593 Bytes
19dc325
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import os
import shutil
from pathlib import Path
from fastapi import UploadFile

UPLOAD_DIR = Path("uploads")
UPLOAD_DIR.mkdir(exist_ok=True)

class FileHandler:
    @staticmethod
    async def save_upload_file(upload_file: UploadFile) -> str:
        try:
            file_path = UPLOAD_DIR / upload_file.filename
            with file_path.open("wb") as buffer:
                shutil.copyfileobj(upload_file.file, buffer)
            return str(file_path)
        except Exception as e:
            # In a real app, log this
            print(f"Error saving file: {e}")
            raise e