@@ -47,15 +47,15 @@ std::condition_variable AwsDoc::S3::upload_variable;
4747*/
4848
4949// snippet-start:[s3.cpp.put_object_async_finished.code]
50- void putObjectAsyncFinished (const Aws::S3::S3Client *s3Client,
50+ void uploadFileAsyncFinished (const Aws::S3::S3Client *s3Client,
5151 const Aws::S3::Model::PutObjectRequest &request,
5252 const Aws::S3::Model::PutObjectOutcome &outcome,
5353 const std::shared_ptr<const Aws::Client::AsyncCallerContext> &context) {
5454 if (outcome.IsSuccess ()) {
55- std::cout << " Success: putObjectAsyncFinished : Finished uploading '"
55+ std::cout << " Success: uploadFileAsyncFinished : Finished uploading '"
5656 << context->GetUUID () << " '." << std::endl;
5757 } else {
58- std::cerr << " Error: putObjectAsyncFinished : " <<
58+ std::cerr << " Error: uploadFileAsyncFinished : " <<
5959 outcome.GetError ().GetMessage () << std::endl;
6060 }
6161
@@ -68,17 +68,17 @@ void putObjectAsyncFinished(const Aws::S3::S3Client *s3Client,
6868// ! Routine which demonstrates adding an object to an Amazon S3 bucket, asynchronously.
6969/* !
7070 \param s3Client: Instance of the S3 Client.
71+ \param request: Instance of the put object request.
7172 \param bucketName: Name of the bucket.
7273 \param fileName: Name of the file to put in the bucket.
7374 \return bool: Function succeeded.
7475*/
7576
7677// snippet-start:[s3.cpp.put_object_async.code]
77- bool AwsDoc::S3::putObjectAsync (const Aws::S3::S3Client &s3Client,
78+ bool AwsDoc::S3::uploadFileAsync (const Aws::S3::S3Client &s3Client,
79+ Aws::S3::Model::PutObjectRequest &request,
7880 const Aws::String &bucketName,
7981 const Aws::String &fileName) {
80- // Create and configure the asynchronous put object request.
81- Aws::S3::Model::PutObjectRequest request;
8282 request.SetBucket (bucketName);
8383 request.SetKey (fileName);
8484
@@ -100,9 +100,9 @@ bool AwsDoc::S3::putObjectAsync(const Aws::S3::S3Client &s3Client,
100100 context->SetUUID (fileName);
101101
102102 // Make the asynchronous put object call. Queue the request into a
103- // thread executor and call the putObjectAsyncFinished function when the
103+ // thread executor and call the uploadFileAsyncFinished function when the
104104 // operation has finished.
105- s3Client.PutObjectAsync (request, putObjectAsyncFinished , context);
105+ s3Client.PutObjectAsync (request, uploadFileAsyncFinished , context);
106106
107107 return true ;
108108}
@@ -135,7 +135,7 @@ int main(int argc, char* argv[])
135135 return 1 ;
136136 }
137137
138- Aws::SDKOptions options;
138+ const Aws::SDKOptions options;
139139 Aws::InitAPI (options);
140140 {
141141 const Aws::String fileName = argv[1 ];
@@ -150,13 +150,18 @@ int main(int argc, char* argv[])
150150 // Create and configure the Amazon S3 client.
151151 // This client must be declared here, as this client must exist
152152 // until the put object operation finishes.
153- Aws::S3::S3ClientConfiguration config;
153+ const Aws::S3::S3ClientConfiguration config;
154154 // Optional: Set to the AWS Region in which the bucket was created (overrides config file).
155155 // config.region = "us-east-1";
156156
157- Aws::S3::S3Client s3Client (config);
157+ const Aws::S3::S3Client s3Client (config);
158158
159- AwsDoc::S3::putObjectAsync (s3Client, bucketName, fileName);
159+ // Create the request object.
160+ // This request object must be declared here, because the object must exist
161+ // until the put object operation finishes.
162+ Aws::S3::Model::PutObjectRequest request;
163+
164+ AwsDoc::S3::uploadFileAsync (s3Client, request, bucketName, fileName);
160165
161166 std::cout << " main: Waiting for file upload attempt..." <<
162167 std::endl << std::endl;
0 commit comments