in s3_common/src/s3_facade.cpp [47:82]
Model::PutObjectOutcome S3Facade::PutObject(
const std::string & file_path,
const std::string & bucket,
const std::string & key)
{
AWS_LOGSTREAM_INFO(__func__, "Upload: "<<file_path<<" to s3://"<<bucket<<"/"<<key);
const std::shared_ptr<Aws::IOStream> file_data =
std::make_shared<Aws::FStream>(file_path.c_str(),
std::ios_base::in | std::ios_base::binary);
if (!file_data->good()) {
AWS_LOGSTREAM_ERROR(__func__, "Upload aborted, file " << file_path << " couldn't be opened for reading");
Aws::StringStream result;
result << "File " << file_path << " couldn't be opened for reading";
return Model::PutObjectOutcome(Aws::Client::AWSError<S3Errors>(S3Errors::INVALID_PARAMETER_VALUE,
"INVALID_PARAMETER_VALUE", Aws::String(result.str()), false));
}
Aws::S3::Model::PutObjectRequest put_object_request;
put_object_request.SetBucket(bucket.c_str());
put_object_request.SetKey(key.c_str());
put_object_request.SetBody(file_data);
if (enable_encryption_) {
put_object_request.SetServerSideEncryption(Aws::S3::Model::ServerSideEncryption::AES256);
} else {
put_object_request.SetServerSideEncryption(Aws::S3::Model::ServerSideEncryption::NOT_SET);
}
auto outcome = s3_client_->PutObject(put_object_request);
if (outcome.IsSuccess()) {
AWS_LOGSTREAM_INFO(__func__, "Successfully uploaded " << file_path << " to s3://" << bucket << "/" << key);
} else {
const auto & error = outcome.GetError();
AWS_LOGSTREAM_ERROR(__func__, "Failed to upload " << file_path << " to s3://" << bucket << "/" << key
<< ": " << error.GetMessage());
}
return outcome;
}