Using the Python client, how can I recursively upload all files in a local directory to Minio while preserving the directory structure?
Asked
Active
Viewed 5,562 times
1 Answers
8
This recursive function uploads all files presuming Minio client is initialized beforehand:
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)
Adapted from https://stackoverflow.com/a/56870303/5964489

Emre
- 933
- 15
- 27