minio.png
本章使用的minIO的前提是需要有一個完善的minIO服務(wù)器
- 最基本的python是有的 python版本在3.6以上..
- 使用pip 安裝minIO pip install minio
初始化MinIO Client
參數(shù) | 描述 |
---|---|
endpoint | 對象存儲服務(wù)URL |
access_key | Access key是唯一標(biāo)識你的賬戶的用戶ID |
secret_key | Secret key是你賬戶的密碼 |
secure | true代表使用HTTPS |
# 官方初始化實例:
from minio import Minio
from minio.error import ResponseError
minioClient = Minio('endpoint',
access_key='access_key',
secret_key='secret_key',
secure=True)
文件上傳實例file-uploader.py
# 引入MinIO包。
from minio import Minio
from minio.error import (ResponseError, BucketAlreadyOwnedByYou,
BucketAlreadyExists)
# 使用endpoint、access key和secret key來初始化minioClient對象次泽。
minioClient = Minio('play.min.io',
access_key='***********************',
secret_key='*********************',
secure=True)
# 調(diào)用make_bucket來創(chuàng)建一個存儲桶了袁。
try:
minioClient.make_bucket("maylogs", location="us-east-1")
except BucketAlreadyOwnedByYou as err:
pass
except BucketAlreadyExists as err:
pass
except ResponseError as err:
raise
else:
try:
minioClient.fput_object('maylogs', 'pumaserver_debug.log', '/tmp/pumaserver_debug.log')
except ResponseError as err:
print(err)
操作API文檔:
- 操作存儲桶
- make_bucket
- list_buckets
- bucket_exists
- remove_bucket
- list_objects
- list_objects_v2
- list_incomplate_uploads
- 存儲桶策略
- 存儲桶通知
- 操作文件對象
- 操作對象
- Presigned操作
借鑒文檔: https://docs.min.io/cn/python-client-quickstart-guide.html