python上传大文件s3_python – 如何在Amazon S3中复制大于5 GB的文件?

As far as I know there’s no rename or move operation, therefore I have

to copy the file to the new location and delete the old one.

这是正确的,对于通过PUT Object – Copy操作的小于5 GB的对象/文件,然后进行DELETE Object操作(这两个在boto中都支持,当然可以参见copy_key()和delete_key()),这很简单:

This implementation of the PUT operation creates a copy of an object

that is already stored in Amazon S3. A PUT copy operation is the same

as performing a GET and then a PUT. Adding the request header,

x-amz-copy-source, makes the PUT operation copy the source object into

the destination bucket.

但是,对于大于5 GB的对象/文件,这是不可能的:

Note

[…] You create a copy of your object up to 5 GB in size in a single atomic

operation using this API. However, for copying an object greater than

5 GB, you must use the multipart upload API. For conceptual

information […], go to 07005 […] [emphasis mine]

import boto

s3 = boto.connect_s3('access', 'secret')

b = s3.get_bucket('destination_bucket')

mp = b.initiate_multipart_upload('tmp/large-copy-test.mp4')

mp.copy_part_from_key('source_bucket', 'path/to/source/key', 1, 0, 999999999)

mp.copy_part_from_key('source_bucket', 'path/to/source/key', 2, 1000000000, 1999999999)

mp.copy_part_from_key('source_bucket', 'path/to/source/key', 3, 2000000000, 2999999999)

mp.copy_part_from_key('source_bucket', 'path/to/source/key', 4, 3000000000, 3999999999)

mp.copy_part_from_key('source_bucket', 'path/to/source/key', 5, 4000000000, 4999999999)

mp.copy_part_from_key('source_bucket', 'path/to/source/key', 6, 5000000000, 5500345712)

mp.complete_upload()

您可能想要研究各自的示例,最终如何在Java或.NET中实现这一点,这可能会提供对通用方法的更多洞察,参见Copying Objects Using the Multipart Upload API。

祝你好运!

附录

请注意以下复制的特点,这很容易被忽略:

When copying an object, you can preserve most of the metadata

(default) or specify new metadata. However, the ACL is not preserved

and is set to private for the user making the request. To override the

default ACL setting, use the x-amz-acl header to specify a new ACL

when generating a copy request. For more information, see Amazon S3

ACLs. [emphasis mine]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值