Multipart upload
With multipart upload you upload an object in several parts. Parts can be sent in parallel and in any order; a failed part is retried on its own. Multipart upload is required for objects over 5 GB and pays off from about 100 MB. All examples use path style and the endpoint https://s3-ch-east.chilistorage.com.
The AWS CLI (aws s3 cp, aws s3 sync), rclone and the AWS SDKs do this automatically. You only need the individual steps if you control the process yourself.
Process
- CreateMultipartUpload starts the upload and returns an
UploadId. - UploadPart uploads each part with
partNumberanduploadIdand returns anETagper part. - CompleteMultipartUpload assembles the parts into the object in the given order.
- If you cancel, AbortMultipartUpload discards all uploaded parts.
Limits
Limit | Value |
|---|---|
Part numbers | 1 to 10,000 |
Size of a part | 5 MiB to 5 GiB |
Last part | May be smaller than 5 MiB |
Maximum object size | 5 TB |
Entries per ListMultipartUploads | At most 1000 |
With 10,000 parts and a 5 TB object, each part must be just over 500 MiB. Choose the part size to match the file size.
Operations
Operation | Method and path | Notes |
|---|---|---|
CreateMultipartUpload |
| Returns the |
UploadPart |
| One part per request |
UploadPartCopy |
| Copy a part from an existing object |
CompleteMultipartUpload |
| Assemble the parts |
AbortMultipartUpload |
| Discard the upload |
ListParts |
| Uploaded parts of one upload |
ListMultipartUploads |
| Open uploads in the bucket |
Operations in detail
CreateMultipartUpload
POST /my-bucket/backup.tar?uploads HTTP/1.1
Host: s3-ch-east.chilistorage.com
Content-Type: application/x-tar
x-amz-meta-source: server01Set metadata (x-amz-meta-*), Content-Type and optionally x-amz-checksum-algorithm here, not on the individual parts.
<InitiateMultipartUploadResult>
<Bucket>my-bucket</Bucket>
<Key>backup.tar</Key>
<UploadId>VXBsb2FkSWQtMTIzNDU2</UploadId>
</InitiateMultipartUploadResult>UploadPart
PUT /my-bucket/backup.tar?partNumber=1&uploadId=VXBsb2FkSWQtMTIzNDU2 HTTP/1.1
Host: s3-ch-east.chilistorage.com
Content-Length: 104857600
Content-MD5: <MD5 of the part, Base64>Header or parameter | Meaning |
|---|---|
| 1 to 10,000, sets the position in the final object |
| From CreateMultipartUpload |
| Checksum of the part, recommended |
The response contains the part's ETag. Keep PartNumber and ETag; you need both for CompleteMultipartUpload. Uploading a part with the same number again replaces the previous one.
UploadPartCopy
Instead of sending data, UploadPartCopy copies a range from an existing object as a part. This is how you copy objects over 5 GB on the server side.
Header | Meaning |
|---|---|
| Source as |
| Byte range, such as |
| Conditions on the source |
CompleteMultipartUpload
POST /my-bucket/backup.tar?uploadId=VXBsb2FkSWQtMTIzNDU2 HTTP/1.1
Host: s3-ch-east.chilistorage.com<CompleteMultipartUpload>
<Part><PartNumber>1</PartNumber><ETag>"a54357aff0632cce46d942af68356b38"</ETag></Part>
<Part><PartNumber>2</PartNumber><ETag>"0c78aef83f66abc1fa1e8477f296d394"</ETag></Part>
</CompleteMultipartUpload>List the parts in ascending PartNumber order. The object only becomes visible with this call. The response contains bucket, key and the ETag of the finished object, and x-amz-version-id if versioning is enabled. The ETag of a multipart object is not an MD5 of the whole file; it ends in -<number of parts>.
AbortMultipartUpload
DELETE /my-bucket/backup.tar?uploadId=VXBsb2FkSWQtMTIzNDU2 HTTP/1.1
Host: s3-ch-east.chilistorage.comDiscards the upload and all parts uploaded so far. The UploadId then accepts no more parts.
ListParts
GET /my-bucket/backup.tar?uploadId=VXBsb2FkSWQtMTIzNDU2&max-parts=100 HTTP/1.1
Host: s3-ch-east.chilistorage.comLists the parts of an ongoing upload with number, size and ETag. Page through long lists with max-parts and part-number-marker. Useful for resuming an interrupted upload.
ListMultipartUploads
GET /my-bucket?uploads&prefix=backup/ HTTP/1.1
Host: s3-ch-east.chilistorage.comLists all uploads in the bucket that were started but neither completed nor aborted.
Parameter | Meaning |
|---|---|
| Only uploads for keys with this prefix |
| Groups keys into |
| 1 to 1000, default 1000 |
| Continue the listing after this key or upload ID |
Example with the AWS CLI
The simple way: aws s3 cp splits large files on its own. Set the part size in the CLI configuration:
aws configure set request_checksum_calculation when_required
aws configure set default.s3.multipart_chunksize 100MB
aws s3 cp backup.tar s3://my-bucket/backup.tar \
--endpoint-url https://s3-ch-east.chilistorage.comThe individual steps with aws s3api, here with two parts of 100 MiB:
EP=https://s3-ch-east.chilistorage.com
split -b 100M backup.tar part-
UPLOAD_ID=$(aws s3api create-multipart-upload --bucket my-bucket --key backup.tar \
--query UploadId --output text --endpoint-url $EP)
aws s3api upload-part --bucket my-bucket --key backup.tar --part-number 1 \
--body part-aa --upload-id "$UPLOAD_ID" --endpoint-url $EP
aws s3api upload-part --bucket my-bucket --key backup.tar --part-number 2 \
--body part-ab --upload-id "$UPLOAD_ID" --endpoint-url $EP
aws s3api list-parts --bucket my-bucket --key backup.tar --upload-id "$UPLOAD_ID" \
--query '{Parts: Parts[].{PartNumber: PartNumber, ETag: ETag}}' --output json \
--endpoint-url $EP > parts.json
aws s3api complete-multipart-upload --bucket my-bucket --key backup.tar \
--upload-id "$UPLOAD_ID" --multipart-upload file://parts.json --endpoint-url $EPAbort an upload:
aws s3api abort-multipart-upload --bucket my-bucket --key backup.tar \
--upload-id "$UPLOAD_ID" --endpoint-url https://s3-ch-east.chilistorage.comClean up incomplete uploads
Parts of an upload that was never completed take up storage but do not appear in any object listing. Check open uploads regularly with list-multipart-uploads, or add a lifecycle rule that discards them automatically. This rule aborts uploads that have been open for 7 days:
aws s3api put-bucket-lifecycle-configuration --bucket my-bucket \
--lifecycle-configuration '{"Rules":[{"ID":"abort-mpu","Status":"Enabled","Filter":{"Prefix":""},"AbortIncompleteMultipartUpload":{"DaysAfterInitiation":7}}]}' \
--endpoint-url https://s3-ch-east.chilistorage.comThe call fully replaces any existing lifecycle configuration of the bucket. Details in Lifecycle & tagging.
Next
- Objects: PutObject and CopyObject
- Lifecycle & tagging: discard incomplete uploads automatically
- Limits: limits at a glance
- Error codes:
NoSuchUpload,InvalidPartand others