Python Boto3 AWS 分段上传语法 [英] Python Boto3 AWS Multipart Upload Syntax

查看:51
本文介绍了Python Boto3 AWS 分段上传语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已成功通过 AWS 进行身份验证并使用 Bucket 对象上的put_object"方法上传文件.现在我想使用 multipart API 来为大文件完成这个.我在这个问题中找到了公认的答案:如何使用 boto3 将 S3 对象保存到文件中

I am successfully authenticating with AWS and using the 'put_object' method on the Bucket object to upload a file. Now I want to use the multipart API to accomplish this for large files. I found the accepted answer in this question: How to save S3 object to a file using boto3

但是在尝试实施时,我收到了未知方法"错误.我究竟做错了什么?我的代码如下.谢谢!

But when trying to implement I am getting "unknown method" errors. What am I doing wrong? My code is below. Thanks!

## Get an AWS Session
self.awsSession = Session(aws_access_key_id=accessKey,
aws_secret_access_key=secretKey,
aws_session_token=session_token,
region_name=region_type)  

 ...          

# Upload the file to S3
s3 = self.awsSession.resource('s3')
s3.Bucket('prodbucket').put_object(Key=fileToUpload, Body=data) # WORKS
#s3.Bucket('prodbucket').upload_file(dataFileName, 'prodbucket', fileToUpload) # DOESNT WORK
#s3.upload_file(dataFileName, 'prodbucket', fileToUpload) # DOESNT WORK

推荐答案

upload_file 方法尚未移植到存储桶资源.现在,您需要直接使用客户端对象来执行此操作:

The upload_file method has not been ported over to the bucket resource yet. For now you'll need to use the client object directly to do this:

client = self.awsSession.client('s3')
client.upload_file(...)

这篇关于Python Boto3 AWS 分段上传语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆