Copying an object using multipart upload
Multipart upload allows you to copy objects as a set of parts. The examples in this section show you how to copy objects greater than 5 GB using the multipart upload API. For more general information about multipart uploads, see Uploading and copying objects using multipart upload.
You can copy objects less than 5 GB in a single operation without using the multipart upload API. For more information, see Copying, moving, and renaming objects.
To copy an object using the low-level API, do the following:
-
Initiate a multipart upload by calling the
AmazonS3Client.initiateMultipartUpload()
method. -
Save the upload ID from the response object that the
AmazonS3Client.initiateMultipartUpload()
method returns. You provide this upload ID for each part-upload operation. -
Copy all of the parts. For each part that you need to copy, create a new instance of the
CopyPartRequest
class. Provide the part information, including the source and destination bucket names, source and destination object keys, upload ID, locations of the first and last bytes of the part, and part number. -
Save the responses of the
AmazonS3Client.copyPart()
method calls. Each response includes theETag
value and part number for the uploaded part. You need this information to complete the multipart upload. -
Call the
AmazonS3Client.completeMultipartUpload()
method to complete the copy operation.
The following sections in the Amazon Simple Storage Service API Reference describe the REST API for
multipart upload. For copying an existing object, use the Upload Part (Copy) API and
specify the source object by adding the x-amz-copy-source
request
header in your request.
You can use these APIs to make your own REST requests, or you can use one of the SDKs we provide. For more information about using Multipart Upload with the AWS CLI, see Using the AWS CLI. For more information about the SDKs, see AWS SDK support for multipart upload.