Boto3 Copy_Object 在大小 > 5GB 时失败

4 python amazon-s3 boto3

我有以下功能

async def _s3_copy_object(self, s3_source, s3_destination):
    source_bucket, source_key = get_s3_bucket_and_key(s3_source)
    destination_bucket, destination_key = get_s3_bucket_and_key(s3_destination)

    print("copying object: {} to {}".format(s3_source, s3_destination))
    source = {'Bucket': source_bucket, 'Key': source_key}
    await self._async_s3.copy_object(CopySource=source,
                                     Bucket=destination_bucket, Key=destination_key,
                                     ServerSideEncryption='AES256',
                                     MetadataDirective='COPY',
                                     TaggingDirective='COPY')
Run Code Online (Sandbox Code Playgroud)

如果文件小于 5gb,这很有效,但如果对象超过 5gb,则失败。

我收到以下错误:

An error occurred (InvalidRequest) when calling the CopyObject operation: The specified copy source is larger than the maximum allowable size for a copy source: 5368709120: 1313
Run Code Online (Sandbox Code Playgroud)

有解决办法吗?

dmu*_*ter 10

您需要使用 boto3copy方法而不是copy_object. 它将执行复制大于 5GB 的对象时所需的分段上传。它还将为您处理线程。