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]