2024-04-15 18:07:25 +08:00
|
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
|
|
|
|
"""
|
|
|
|
|
|
@Project :trinity_client
|
|
|
|
|
|
@File :upload_image.py
|
|
|
|
|
|
@Author :周成融
|
|
|
|
|
|
@Date :2023/8/28 13:49:20
|
|
|
|
|
|
@detail :
|
|
|
|
|
|
"""
|
|
|
|
|
|
import io
|
|
|
|
|
|
import logging
|
2024-04-16 15:51:03 +08:00
|
|
|
|
|
2024-04-25 10:48:32 +08:00
|
|
|
|
import cv2
|
2024-04-16 15:51:03 +08:00
|
|
|
|
from PIL import Image
|
2024-04-15 18:07:25 +08:00
|
|
|
|
from minio import Minio
|
|
|
|
|
|
|
|
|
|
|
|
from app.core.config import *
|
|
|
|
|
|
|
2024-04-16 15:51:03 +08:00
|
|
|
|
minio_client = Minio(MINIO_URL, access_key=MINIO_ACCESS, secret_key=MINIO_SECRET, secure=MINIO_SECURE)
|
2024-04-15 18:07:25 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upload_png_sd(image, user_id, category, object_name):
|
|
|
|
|
|
try:
|
2024-04-25 10:48:32 +08:00
|
|
|
|
_, img_byte_array = cv2.imencode('.jpg', image)
|
2024-04-16 15:51:03 +08:00
|
|
|
|
minio_req = minio_client.put_object(
|
|
|
|
|
|
GI_MINIO_BUCKET,
|
|
|
|
|
|
f'{user_id}/{category}/{object_name}',
|
2024-04-25 10:48:32 +08:00
|
|
|
|
io.BytesIO(img_byte_array),
|
|
|
|
|
|
len(img_byte_array),
|
2024-04-16 15:51:03 +08:00
|
|
|
|
content_type='image/jpeg'
|
|
|
|
|
|
)
|
|
|
|
|
|
image_url = f"aida-users/{minio_req.object_name}"
|
2024-04-15 18:07:25 +08:00
|
|
|
|
return image_url
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
logging.warning(f"upload_png_mask runtime exception : {e}")
|