Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions,
see Getting Started with Amazon Web Services in China
(PDF).
Use CreateMultipartUpload
with an Amazon SDK or CLI
The following code examples show how to use CreateMultipartUpload
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in
context in the following code examples:
- C++
-
- SDK for C++
-
//! Create a multipart upload.
/*!
\param bucket: The name of the S3 bucket where the object will be uploaded.
\param key: The unique identifier (key) for the object within the S3 bucket.
\param client: The S3 client instance used to perform the upload operation.
\return Aws::String: Upload ID or empty string if failed.
*/
Aws::String
AwsDoc::S3::createMultipartUpload(const Aws::String &bucket, const Aws::String &key,
Aws::S3::Model::ChecksumAlgorithm checksumAlgorithm,
const Aws::S3::S3Client &client) {
Aws::S3::Model::CreateMultipartUploadRequest request;
request.SetBucket(bucket);
request.SetKey(key);
if (checksumAlgorithm != Aws::S3::Model::ChecksumAlgorithm::NOT_SET) {
request.SetChecksumAlgorithm(checksumAlgorithm);
}
Aws::S3::Model::CreateMultipartUploadOutcome outcome =
client.CreateMultipartUpload(request);
Aws::String uploadID;
if (outcome.IsSuccess()) {
uploadID = outcome.GetResult().GetUploadId();
} else {
std::cerr << "Error creating multipart upload: " << outcome.GetError().GetMessage() << std::endl;
}
return uploadID;
}
- CLI
-
- Amazon CLI
-
The following command creates a multipart upload in the bucket my-bucket
with the key multipart/01
:
aws s3api create-multipart-upload --bucket my-bucket
--key 'multipart/01
'
Output:
{
"Bucket": "my-bucket",
"UploadId": "dfRtDYU0WWCCcH43C3WFbkRONycyCpTJJvxu2i5GYkZljF.Yxwh6XG7WfS2vC4to6HiV6Yjlx.cph0gtNBtJ8P3URCSbB7rjxI5iEwVDmgaXZOGgkk5nVTW16HOQ5l0R",
"Key": "multipart/01"
}
The completed file will be named 01
in a folder called multipart
in the bucket my-bucket
. Save the upload ID, key and bucket name for use with the upload-part
command.
- Rust
-
- SDK for Rust
-
let multipart_upload_res: CreateMultipartUploadOutput = client
.create_multipart_upload()
.bucket(&bucket_name)
.key(&key)
.send()
.await
.unwrap();
For a complete list of Amazon SDK developer guides and code examples, see
Using this service with an Amazon SDK.
This topic also includes information about getting started and details about previous SDK versions.