我正在开发一个包含上载模块的Python应用程序,核心功能从队列中提取.png图像,并使用Boto3客户端将其上载到特定存储桶。
问题在于,有时(并非总是)图像仅部分上传。例如当我下载有缺陷的图像时,它似乎被裁剪了。
当我手动上传图像(使用FTP / SSH客户端)时,图像已完美上传。
以下是我的核心功能,请注意,我正在使用upload_fileobj()
和进度条机制的回调。
def upload_file_aws(self):
s3 = boto3.client('s3', aws_access_key_id=self.aws_access_key,
aws_secret_access_key=self.aws_secret_key)
if (not self.uploader.queue.empty()):
file = self.uploader.queue.get()
with open(file, 'rb') as f:
aws_format = '%s' % AppObject.file_path_dic.get(file)
s3.upload_fileobj(f, self.bucket_name, aws_format, Callback=ProgressBarInit(file))
以前有人遇到过这个问题吗? 他们在Amazon的doc文件中声明boto3协议不支持部分上传。
答案 0 :(得分:0)
对于尺寸大于5 MB
的较大图像,很有可能会发生这种情况。
您应该为multipart
e upload
个对象使用larg
size
。
这是multipart
上传的基本代码示例。
import boto3
def upload_file( filename ):
session = boto3.Session()
s3_client = session.client( 's3' )
try:
print "Uploading file:", filename
tc = boto3.s3.transfer.TransferConfig()
t = boto3.s3.transfer.S3Transfer( client=s3_client,
config=tc )
t.upload_file( filename, 'my-bucket-name', 'name-in-s3.dat' )
except Exception as e:
print "Error uploading: %s" % ( e )