Yolov/_minio.py

28 lines
787 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# minio_client.py
from minio import Minio
import os
class MinioUploader:
def __init__(self, config):
self.bucket = config['BucketName']
self.client = Minio(
config['Endpoint'],
access_key=config['AccessKey'],
secret_key=config['SecretKey'],
secure=config['UseSSL']
)
# 自动创建 bucket如不存在
if not self.client.bucket_exists(self.bucket):
self.client.make_bucket(self.bucket)
def upload_file(self, file_path, object_name=None):
if not object_name:
object_name = os.path.basename(file_path)
self.client.fput_object(
bucket_name=self.bucket,
object_name=object_name,
file_path=file_path,
)