@@ -47,15 +47,15 @@ std::condition_variable AwsDoc::S3::upload_variable;
47
47
*/
48
48
49
49
// 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,
51
51
const Aws::S3::Model::PutObjectRequest &request,
52
52
const Aws::S3::Model::PutObjectOutcome &outcome,
53
53
const std::shared_ptr<const Aws::Client::AsyncCallerContext> &context) {
54
54
if (outcome.IsSuccess ()) {
55
- std::cout << " Success: putObjectAsyncFinished : Finished uploading '"
55
+ std::cout << " Success: uploadFileAsyncFinished : Finished uploading '"
56
56
<< context->GetUUID () << " '." << std::endl;
57
57
} else {
58
- std::cerr << " Error: putObjectAsyncFinished : " <<
58
+ std::cerr << " Error: uploadFileAsyncFinished : " <<
59
59
outcome.GetError ().GetMessage () << std::endl;
60
60
}
61
61
@@ -68,17 +68,17 @@ void putObjectAsyncFinished(const Aws::S3::S3Client *s3Client,
68
68
// ! Routine which demonstrates adding an object to an Amazon S3 bucket, asynchronously.
69
69
/* !
70
70
\param s3Client: Instance of the S3 Client.
71
+ \param request: Instance of the put object request.
71
72
\param bucketName: Name of the bucket.
72
73
\param fileName: Name of the file to put in the bucket.
73
74
\return bool: Function succeeded.
74
75
*/
75
76
76
77
// 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,
78
80
const Aws::String &bucketName,
79
81
const Aws::String &fileName) {
80
- // Create and configure the asynchronous put object request.
81
- Aws::S3::Model::PutObjectRequest request;
82
82
request.SetBucket (bucketName);
83
83
request.SetKey (fileName);
84
84
@@ -100,9 +100,9 @@ bool AwsDoc::S3::putObjectAsync(const Aws::S3::S3Client &s3Client,
100
100
context->SetUUID (fileName);
101
101
102
102
// 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
104
104
// operation has finished.
105
- s3Client.PutObjectAsync (request, putObjectAsyncFinished , context);
105
+ s3Client.PutObjectAsync (request, uploadFileAsyncFinished , context);
106
106
107
107
return true ;
108
108
}
@@ -135,7 +135,7 @@ int main(int argc, char* argv[])
135
135
return 1 ;
136
136
}
137
137
138
- Aws::SDKOptions options;
138
+ const Aws::SDKOptions options;
139
139
Aws::InitAPI (options);
140
140
{
141
141
const Aws::String fileName = argv[1 ];
@@ -150,13 +150,18 @@ int main(int argc, char* argv[])
150
150
// Create and configure the Amazon S3 client.
151
151
// This client must be declared here, as this client must exist
152
152
// until the put object operation finishes.
153
- Aws::S3::S3ClientConfiguration config;
153
+ const Aws::S3::S3ClientConfiguration config;
154
154
// Optional: Set to the AWS Region in which the bucket was created (overrides config file).
155
155
// config.region = "us-east-1";
156
156
157
- Aws::S3::S3Client s3Client (config);
157
+ const Aws::S3::S3Client s3Client (config);
158
158
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);
160
165
161
166
std::cout << " main: Waiting for file upload attempt..." <<
162
167
std::endl << std::endl;
0 commit comments