28 lines
787 B
Python
28 lines
787 B
Python
# 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,
|
||
)
|