Python Minio 上传文件同时配置文件的公共读权限:
minioClient.put_object配置下metadata 中x-amz-acl即可(有效值:private | public-read | public-read-write)
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Import Minio library.
import os
import sys
from minio import Minio
minioClient = Minio('s3-xxxxxxxxxxxxx',
access_key='xxxxxxx',
secret_key='xxxxxxxxxx',
secure=True)
file_path = sys.argv[1]
file_name = sys.argv[1].split('/')[-1]
s3_dir = sys.argv[2] if len(sys.argv) >= 3 and sys.argv[2] else "daily-build/artifacts/"
upload_file_name = sys.argv[3] if len(sys.argv) >= 4 and sys.argv[3] else file_name
with open(file_path, 'rb') as file_data:
file_stat = os.stat(file_path)
print(file_stat)
metadata={'x-amz-acl': 'public-read'}
print(minioClient.put_object('bukect_name', '%s%s' % (s3_dir,upload_file_name),file_data, file_stat.st_size,metadata=metadata))