AWS 文檔 AWS SDK示例 GitHub 回購中有更多SDK示例。
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
搭CreateMultipartUpload
配 AWS SDK或使用 CLI
下列程式碼範例會示範如何使用CreateMultipartUpload
。
動作範例是大型程式的程式碼摘錄,必須在內容中執行。您可以在下列程式碼範例的內容中看到此動作:
- C++
-
- SDK對於 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
-
- AWS CLI
-
以下命令my-bucket
使用密鑰multipart/01
在存儲桶中創建一個多部分上傳:
aws s3api create-multipart-upload --bucket my-bucket
--key 'multipart/01
'
輸出:
{
"Bucket": "my-bucket",
"UploadId": "dfRtDYU0WWCCcH43C3WFbkRONycyCpTJJvxu2i5GYkZljF.Yxwh6XG7WfS2vC4to6HiV6Yjlx.cph0gtNBtJ8P3URCSbB7rjxI5iEwVDmgaXZOGgkk5nVTW16HOQ5l0R",
"Key": "multipart/01"
}
完成的文件將在存儲桶01
中名為的文件夾multipart
中命名my-bucket
。儲存上傳 ID、金鑰和值區名稱,以便與upload-part
指令搭配使用。
- Rust
-
- SDK對於銹
-
let multipart_upload_res: CreateMultipartUploadOutput = client
.create_multipart_upload()
.bucket(&bucket_name)
.key(&key)
.send()
.await
.unwrap();