gpt4 book ai didi

minio - 如何使用 Python 将目录上传到 Minio

转载 作者:行者123 更新时间:2023-12-02 16:18:06 25 4
gpt4 key购买 nike

使用Python客户端,如何递归上传本地目录下的所有文件到Minio,同时保留目录结构?

最佳答案

此递归函数上传所有文件,前提是 Minio 客户端已预先初始化:

import glob

def upload_local_directory_to_minio(local_path, bucket_name, minio_path):
assert os.path.isdir(local_path)

for local_file in glob.glob(local_path + '/**'):
local_file = local_file.replace(os.sep, "/") # Replace \ with / on Windows
if not os.path.isfile(local_file):
upload_local_directory_to_minio(
local_file, bucket_name, minio_path + "/" + os.path.basename(local_file))
else:
remote_path = os.path.join(
minio_path, local_file[1 + len(local_path):])
remote_path = remote_path.replace(
os.sep, "/") # Replace \ with / on Windows
client.fput_object(bucket_name, remote_path, local_file)

改编自https://stackoverflow.com/a/56870303/5964489

关于minio - 如何使用 Python 将目录上传到 Minio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66136763/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com