Boto3最近有一项自定义功能,可以帮助您(其中包括其他方面)。它当前在低级S3客户端上公开,可以这样使用:
s3_client = boto3.client('s3')open('hello.txt').write('Hello, world!')# Upload the file to S3s3_client.upload_file('hello.txt', 'MyBucket', 'hello-remote.txt')# Download the file from S3s3_client.download_file('MyBucket', 'hello-remote.txt', 'hello2.txt')print(open('hello2.txt').read())这些功能将自动处理读取/写入文件,以及并行并行处理大文件。
请注意,
s3_client.download_file这不会创建目录。可以将其创建为
pathlib.Path('/path/to/file.txt').parent.mkdir(parents=True,exist_ok=True)。


