29 lines
930 B
Python
29 lines
930 B
Python
import uuid
|
|
from minio import Minio
|
|
from app.core.config import settings
|
|
|
|
class StorageService:
|
|
client = Minio(
|
|
settings.MINIO_ENDPOINT,
|
|
access_key=settings.MINIO_ROOT_USER,
|
|
secret_key=settings.MINIO_ROOT_PASSWORD,
|
|
secure=settings.MINIO_SECURE
|
|
)
|
|
BUCKET_NAME = "vehicle-documents"
|
|
|
|
@classmethod
|
|
async def upload_document(cls, file_bytes: bytes, file_name: str, folder: str) -> str:
|
|
if not cls.client.bucket_exists(cls.BUCKET_NAME):
|
|
cls.client.make_bucket(cls.BUCKET_NAME)
|
|
|
|
# Egyedi fájlnév generálása az ütközések elkerülésére
|
|
unique_name = f"{folder}/{uuid.uuid4()}_{file_name}"
|
|
|
|
from io import BytesIO
|
|
cls.client.put_object(
|
|
cls.BUCKET_NAME,
|
|
unique_name,
|
|
BytesIO(file_bytes),
|
|
len(file_bytes)
|
|
)
|
|
return f"{cls.BUCKET_NAME}/{unique_name}" |