Spaces:
Running
Running
File size: 975 Bytes
0bd4ab4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """
Utilitaires fichiers
"""
import os
from typing import Optional
from app.core.settings import settings
class FileHandler:
"""Gestion des fichiers"""
@staticmethod
def ensure_upload_dir():
"""Crée le répertoire d'upload s'il n'existe pas"""
os.makedirs(settings.UPLOAD_DIR, exist_ok=True)
@staticmethod
def save_uploaded_file(file_content: bytes, filename: str) -> str:
"""Sauvegarde un fichier uploadé"""
FileHandler.ensure_upload_dir()
file_path = os.path.join(settings.UPLOAD_DIR, filename)
with open(file_path, 'wb') as f:
f.write(file_content)
return file_path
@staticmethod
def delete_file(file_path: str) -> bool:
"""Supprime un fichier"""
try:
if os.path.exists(file_path):
os.remove(file_path)
return True
except Exception:
pass
return False
|