我在s3://hello/sir
之类的路径上有一个存储桶。我想将文件上传到sir
文件夹中。到目前为止,我已经尝试了很多方法,无法将文件推送到s3上。我可以在hello
路径上上传。这就是我尝试过的
s3 = boto3.resource('s3')
s3.Bucket('hello').upload_file('my.txt', 'sir/my.txt')
答案 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/
路径中看到文件。您可以参考以下屏幕截图:
在使用API时,我正在重命名本地文件local-file.txt
-> sample.txt
,但是您可以保留相同的名称,这是完全可选的。
您可以引用 upload_file() API here。