Python3之minio读取

1、读取bucket下面的xx.txt文件,返回str

import minio

MINIO_CONF = {
        'endpoint': '127.0.0.1:9000',
        'access_key': 'name',
        'secret_key': 'pwd',
        'secure': False
    }

def latest_minio_find(bucket: str):
    client = minio.Minio(**MINIO_CONF)
    if not client.bucket_exists(bucket):
        return None
    data = client.get_object(bucket, 'xx.txt')
    return data.data.decode('utf-8')

2、上传文件

	# 上传zip文件
    client.fput_object(bucket_name=bucket, object_name=file_name,
                       file_path=file_path,
                       content_type='application/zip'
                       )

3、改写文件内容

		date_str ='202001011000'
        stream = io.BytesIO(date_str)
        client.put_object(bucket_name=bucket,
                          object_name="xx.txt",
                          data=stream, length=len(date_str),
                          content_type='text/plain')

你可能感兴趣的:(Python,minio)