amazon-s3 - 无法通过我的 DLL 项目(用 C++ 编写)连接到 AWS S3 存储桶
问题描述
我正在尝试将 AWS S3 存储桶集成到我的项目中(一个用 C++ 编写的 DLL)。我成功地基于为 C++ 提供的 AWS SDK 创建了一个独立的控制台应用程序,该应用程序连接到存储桶并根据要求上传特定文件。当我使用相同的代码并添加所有依赖项(dll 库和头文件)时,DLL 项目编译没有错误。但是,在运行时同样无法连接到 s3 实例。没有明显的错误,但我可以弄清楚代码无法检索任何存储桶列表。我确定我错过了一些东西,但不确定它是什么。仅供参考,为简单起见,我尝试使用以下命令连接到 AWS 存储桶一次:InitAPI(options) { ……….. ……….. } Aws::ShutdownAPI(options)
我的代码的简单概述:
bool FindTheBucket(const Aws::S3::S3Client& s3Client,
const Aws::String& bucketName)
{
Aws::S3::Model::ListBucketsOutcome outcome = s3Client.ListBuckets();
if (outcome.IsSuccess())
{
Aws::Vector<Aws::S3::Model::Bucket> bucket_list =
outcome.GetResult().GetBuckets();
for (Aws::S3::Model::Bucket const& bucket : bucket_list)
{
if (bucket.GetName() == bucketName)
return true;
}
return false;
}
else
return false;
}
以及调用 SDK 的主要函数中的代码段......
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;
Aws::InitAPI(options);
{
Aws::String bucket_name = "testbucket"; // a bucket of the same name exists
Aws::String region = "us-west-2";
Aws::Client::ClientConfiguration config;
config.region = region;
Aws::S3::S3Client s3_client(config);
if (FindTheBucket(s3_client, bucket_name))
{
//do the needful
std::ofstream myFile(str.c_str());
myFile.close();
PutObjectBuffer(bucket_name, str.c_str(),
layerstr, region);
}
else
{
//some code…
}
}
Aws::ShutdownAPI(options);
解决方案
推荐阅读
- xamarin.android - Xamarin.Android PDFViewer 库
- ios - 如何在 Xcode 的属性检查器中显示辅助功能窗格
- ssl - 如何将证书添加到 Kong。发出 https 请求
- python - gitlab-ci 的 Unicode 错误-不在工作站上
- wordpress - 使用 .htaccess 屏蔽 url 中的域
- sql - 使用来自一个表的数据连接到另一个包含两个键列的表来创建数据的结果集
- python - PySpark:根据列 Y 和 ID 中的先前值计算列 X 中的值
- reactjs - 如何从 create-react-app 获取类声明?
- python - 如何在pycharm中禁用错误消息“打印关键字不能用作python 2中的标识符”?
- angular - 如何立即触发 httpclient 请求?