官方文档:http://docs.minio.org.cn/docs/master/python-client-api-reference
| 操作存储桶 | 操作对象 | Presigned操作 | 存储桶策略/通知 |
| make_bucket | get_object | presigned_get_object | get_bucket_policy |
| :—- | :—- | :—- | :—- |
| list_buckets | put_object | presigned_put_object | set_bucket_policy |
| bucket_exists | copy_object | presigned_post_policy | get_bucket_notification |
| remove_bucket | stat_object | | set_bucket_notification |
| list_objects | remove_object | | remove_all_bucket_notification |
| list_objects_v2 | remove_objects | | listen_bucket_notification |
| list_incomplete_uploads | remove_incomplete_upload | | |
| | fput_object | | |
| | fget_object | | |
| | get_partial_object | | |
from minio import Miniofrom minio.error import ServerErrorfrom datetime import timedeltaMINIO_CONF = {'endpoint': '127.0.0.1:9000','access_key': 'AKIAIOSFODNN7EXAMPLE','secret_key': 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY','secure': False}minioClient = Minio(**MINIO_CONF)def make_bucket(name: str = 'mayimages'):# 调用make_bucket来创建一个存储桶。try:minioClient.make_bucket(name, location="us-east-1")except Exception as err:print('make_bucket err:', err)def fput_object(name: str = 'mayimages'):# 上传文件try:minioClient.fput_object(name, 'images.jpg', './images.jpg')except Exception as err:print('fput_object err:', err)def list_buckets():# 桶列表buckets = minioClient.list_buckets()for bucket in buckets:print(bucket.name, bucket.creation_date)def get_object(name: str = 'mayimages'):# 获取文件try:data = minioClient.get_object(name, 'images.jpg')print(data.data)except ServerError as err:print(err)def remove_object(name: str = 'mayimages'):# 删除一个文件try:minioClient.remove_object(name, 'images.jpg')except ServerError as err:print(err)def presigned_get_object(name: str = 'mayimages'):# 生成一个对外个HTTP 下载链接try:url = minioClient.presigned_get_object(name, 'images.jpg', expires=timedelta(minutes=1))print(url)except ServerError as err:print(err)
