1. 情况:minio的list_objects查找不到指定prefix前缀的对象会自动找字典序后面的对象
比如我要找example
命名的对象文件夹,但是服务器上只有example-1
,那么他就会自动找example-1
objects = minio_lient.list_objects(self.bucket_name, prefix=self.prefix, recursive=True)
2. 解决方法
- prefix设置完整路径,例如只想找
example
的对象同时避免example-1
的影响,就加个反斜杠代表名称结束example/
from minio import Minio
from minio.error import ResponseError
# 初始化 MinIO 客户端
client = Minio("play.min.io", access_key="YOURACCESSKEY", secret_key="YOURSECRETKEY", secure=True)
# 列出存储桶中指定前缀的对象
try:
objects = client.list_objects("my-bucket", prefix="example/", recursive=True)
for obj in objects:
print(obj.object_name)
except ResponseError as err:
print(err)