所以我正在尝试使用 aws sdk cpp 将本地文件上传到 aws s3。这是我从此处的问题中获取的示例代码
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/core/utils/HashingUtils.h>
#include <aws/s3/model/PutObjectRequest.h>
#include <iostream>
#include <fstream>
using namespace Aws::S3::Model;
using namespace std;
using namespace Aws::Utils;
static const char* KEY = "try.txt";
static const char* BUCKET = "bucket-name";
int main()
{
Aws::SDKOptions options;
Aws::InitAPI(options);
Aws::Client::ClientConfiguration myConf;
myConf.region = Aws::Region::US_EAST_2;
Aws::S3::S3Client s3_client(myConf);
const Aws::String bucket_name = BUCKET;
const Aws::String key_name = KEY;
const Aws::String dir_name = "C:/Users/linda.naoui/source/repos/Upload s3";
std::cout << "Uploading " << key_name << " to S3 bucket: " <<
bucket_name << std::endl;
Aws::S3::Model::PutObjectRequest object_request;
object_request.WithBucket(bucket_name).WithKey(key_name);
auto input_data = Aws::MakeShared<Aws::FStream>(key_name.c_str(), dir_name.c_str(), std::ios_base::in);
object_request.SetBody(input_data);
auto put_object_outcome = s3_client.PutObject(object_request);
if (put_object_outcome.IsSuccess()) {
std::cout << "Done!" << std::endl;
}
else {
std::cout << "PutObject error: " <<
put_object_outcome.GetError().GetExceptionName() << " " <<
put_object_outcome.GetError().GetMessage() << std::endl;
}
Aws::ShutdownAPI(options);
return 0;
}
我有很多与 dll 导入相关的类似错误,我使用 Nuget 包安装了 aws s3 sdk 和 aws sdk 核心,我目前在 Visual Studio 2019 上。
严重性代码 描述 项目文件行抑制状态错误 LNK2019 无法解析的外部符号“__declspec(dllimport) public: __thiscall Aws::S3::Model::PutObjectResult::~PutObjectResult(void)” (__imp_??1PutObjectResult@Model@S3@Aws @@QAE@XZ) 在函数“public: __thiscall Aws::Utils::Outcome >::~Outcome >(void)”中引用 (??1?$Outcome@VPutObjectResult@Model@S3@Aws@@V?$ AWSError@W4S3Errors@S3@Aws@@@Client@4@@Utils@Aws@@QAE@XZ) 上传 s3 C:\Users\linda.naoui\source\repos\Upload s3\Upload s3\S3.obj 1
严重性代码描述项目文件行抑制状态错误 LNK2019 未解析的外部符号“__declspec(dllimport) void __cdecl Aws::InitAPI(struct Aws::SDKOptions const &)”(__imp_?InitAPI@Aws@@YAXABUSDKOptions@1@@Z) 引用在函数 _main Upload s3 C:\Users\linda.naoui\source\repos\Upload s3\Upload s3\S3.obj 1
我不确定问题是否是因为链接窗口是空的