如何使用Boto将文件上传到S3存储桶上的确切位置

时间:2020-08-20 03:14:34

标签: python amazon-s3 boto3

我在s3://hello/sir之类的路径上有一个存储桶。我想将文件上传到sir文件夹中。到目前为止,我已经尝试了很多方法,无法将文件推送到s3上。我可以在hello路径上上传。这就是我尝试过的 s3 = boto3.resource('s3')

s3.Bucket('hello').upload_file('my.txt', 'sir/my.txt')

1 个答案:

答案 0 :(得分:1)

这是我为我努力的工作:

import boto3


client = boto3.client('s3')
client.upload_file('/Users/data/local-file.txt', 'temp-data-user-bucket',
                   'hello/sir/sample.txt')

运行上述代码后,我可以在/hello/sir/路径中看到文件。您可以参考以下屏幕截图:

enter image description here

在使用API​​时,我正在重命名本地文件local-file.txt-> sample.txt,但是您可以保留相同的名称,这是完全可选的。

您可以引用 upload_file() API here