擅长:python、mysql、java
<p>有一个定制,最近进入Boto3有助于这一点(除其他外)。它当前在低级S3客户机上公开,可以如下使用:</p>
<pre><code>s3_client = boto3.client('s3')
open('hello.txt').write('Hello, world!')
# Upload the file to S3
s3_client.upload_file('hello.txt', 'MyBucket', 'hello-remote.txt')
# Download the file from S3
s3_client.download_file('MyBucket', 'hello-remote.txt', 'hello2.txt')
print(open('hello2.txt').read())
</code></pre>
<p>这些函数将自动处理读/写文件,以及对大型文件并行执行多部分上载。</p>
<p>请注意,<code>s3_client.download_file</code>不会创建目录。它可以创建为<code>pathlib.Path('/path/to/file.txt').parent.mkdir(parents=True, exist_ok=True)</code>。</p>