2025-06-10 17:41:32 +08:00
|
|
|
import base64
|
|
|
|
|
|
|
|
|
|
from minio import Minio
|
|
|
|
|
|
2025-12-30 16:49:08 +08:00
|
|
|
from app.core.config import settings
|
2025-06-10 17:41:32 +08:00
|
|
|
|
2025-12-30 16:49:08 +08:00
|
|
|
minio_client = Minio(settings.MINIO_URL, access_key=settings.MINIO_ACCESS, secret_key=settings.MINIO_SECRET, secure=settings.MINIO_SECURE)
|
2025-06-10 17:41:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def minio_url_to_base64(minio_url: str) -> str:
|
|
|
|
|
bucket_name, object_name = minio_url.split("/", 1)
|
2025-12-30 16:49:08 +08:00
|
|
|
response = minio_client.get_object(bucket_name, object_name)
|
2025-06-10 17:41:32 +08:00
|
|
|
try:
|
|
|
|
|
image_data = response.read()
|
|
|
|
|
return base64.b64encode(image_data).decode('utf-8')
|
|
|
|
|
except Exception as e:
|
|
|
|
|
raise RuntimeError(f"Failed to get object: {e}")
|
|
|
|
|
finally:
|
|
|
|
|
if 'response' in locals():
|
2025-12-30 16:49:08 +08:00
|
|
|
response.close()
|