无法通过我的 DLL 项目用 C++ 编写连接到 AWS S3 存储桶

问题描述

我正在尝试将 AWS S3 存储桶集成到我的项目(用 C++ 编写的 DLL)中。我成功地基于为 C++ 提供的 AWS 开发工具包创建了一个独立的控制台应用程序,该应用程序连接到存储桶并根据要求上传特定文件。 当我使用相同的代码添加所有依赖项(dll 库和头文件)时,DLL 项目编译没有错误。但是,在运行时无法连接到 s3 实例。没有可见的错误,但我可以弄清楚代码无法检索任何桶列表。我确定我错过了一些东西,但不确定它是什么。 仅供参考,为简单起见,我尝试使用以下命令仅连接到 AWS 存储桶一次: InitAPI(选项) { ………… ………… } Aws::ShutdownAPI( 选项)

我的代码的简单概述:

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);

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)