minio测试.py 744 B

1234567891011121314151617181920212223242526272829
  1. from minio import Minio
  2. client = Minio(
  3. "192.168.77.249:9000",
  4. access_key="pZEwCGnpNN05KPnmC2Yh",
  5. secret_key="KfJRuWiv9pVxhIMcFqbkv8hZT9SnNTZ6LPx592D4",
  6. secure=False
  7. )
  8. bucket_name = "grading"
  9. try:
  10. # 2. 检查存储桶是否存在
  11. found = client.bucket_exists(bucket_name)
  12. if not found:
  13. client.make_bucket(bucket_name)
  14. print(f"存储桶 {bucket_name} 已创建")
  15. else:
  16. print(f"存储桶 {bucket_name} 已存在")
  17. # 4. 列出该目录(桶)下的所有文件
  18. objects = client.list_objects(bucket_name, recursive=True)
  19. for obj in objects:
  20. print(f"对象名称: {obj.object_name}, 大小: {obj.size} bytes")
  21. except Exception as e:
  22. print(f"发生错误: {e}")