Docs

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

  1. CreateMultipartUpload starts the upload and returns an UploadId.
  2. UploadPart uploads each part with partNumber and uploadId and returns an ETag per part.
  3. CompleteMultipartUpload assembles the parts into the object in the given order.
  4. 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

POST /{bucket}/{key}?uploads

Returns the UploadId

UploadPart

PUT /{bucket}/{key}?partNumber={n}&uploadId={id}

One part per request

UploadPartCopy

PUT /{bucket}/{key}?partNumber={n}&uploadId={id} with x-amz-copy-source

Copy a part from an existing object

CompleteMultipartUpload

POST /{bucket}/{key}?uploadId={id}

Assemble the parts

AbortMultipartUpload

DELETE /{bucket}/{key}?uploadId={id}

Discard the upload

ListParts

GET /{bucket}/{key}?uploadId={id}

Uploaded parts of one upload

ListMultipartUploads

GET /{bucket}?uploads

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: server01

Set 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

partNumber

1 to 10,000, sets the position in the final object

uploadId

From CreateMultipartUpload

Content-MD5 or x-amz-checksum-*

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

x-amz-copy-source

Source as /{bucket}/{key}

x-amz-copy-source-range

Byte range, such as bytes=0-104857599

x-amz-copy-source-if-match, -if-none-match, -if-modified-since, -if-unmodified-since

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.com

Discards 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.com

Lists 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.com

Lists all uploads in the bucket that were started but neither completed nor aborted.

Parameter

Meaning

prefix

Only uploads for keys with this prefix

delimiter

Groups keys into CommonPrefixes

max-uploads

1 to 1000, default 1000

key-marker, upload-id-marker

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.com

The 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 $EP

Abort an upload:

aws s3api abort-multipart-upload --bucket my-bucket --key backup.tar \
  --upload-id "$UPLOAD_ID" --endpoint-url https://s3-ch-east.chilistorage.com

Clean 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.com

The call fully replaces any existing lifecycle configuration of the bucket. Details in Lifecycle & tagging.

Next