使用 c++ S3 SDK,带有 Minio 的 ListObjecsV2 不返回任何结果

With c++ S3 SDK, ListObjecsV2 with Minio returning no results

下面是一些将对象放入 s3 存储桶、取回它并尝试列出该存储桶的代码。 put 和 get 都工作正常,但列出桶 returns 没有键(但没有错误)。我可以使用 golang api 和相同的参数(存储桶名称和空前缀)列出存储桶。为什么不列出存储桶?

Aws::SDKOptions opts;

opts.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Debug;
Aws::InitAPI(opts);

Aws::Auth::AWSCredentials credentials;
Aws::Client::ClientConfiguration config;
Aws::S3::S3Client client;

credentials.SetAWSAccessKeyId("accesskey");
credentials.SetAWSSecretKey("secretkey");
config.endpointOverride = "localhost:5553";
config.scheme = Aws::Http::Scheme::HTTP;
config.verifySSL = false;
client = Aws::S3::S3Client(credentials, config);

const char* bucket = "buck";
const char* key = "buck/key";

// Putting works!
//
Aws::S3::Model::PutObjectRequest pRequest;
pRequest.SetBucket(bucket);
pRequest.SetKey(key);

auto stream = Aws::MakeShared<Aws::StringStream>("tag", "some data");
pRequest.SetBody(stream);

Aws::S3::Model::PutObjectOutcome pOutcome = client.PutObject(pRequest);

if (!pOutcome.IsSuccess())
{
    printf("put failed S3 because %s: %s\n",
           pOutcome.GetError().GetExceptionName().c_str(),
           pOutcome.GetError().GetMessage().c_str());
    printf("\n\n\n\n");
    assert(false);
}

printf("object put\n");

// Getting works!
//
Aws::S3::Model::GetObjectRequest gRequest;
gRequest.SetBucket(bucket);
gRequest.SetKey(key);

Aws::S3::Model::GetObjectOutcome gOutcome = client.GetObject(gRequest);

if (!gOutcome.IsSuccess())
{
    printf("get failed S3 because %s: %s\n",
           gOutcome.GetError().GetExceptionName().c_str(),
           gOutcome.GetError().GetMessage().c_str());
    printf("\n\n\n\n");
    assert(false);
}

printf("object got\n");

char buf[1000];
memset(buf, 0, 1000);
gOutcome.GetResult().GetBody().read(buf, 1000);

printf("object say '%s'\n", buf);

// THIS IS THE PROBLEMATIC CODE
//
Aws::S3::Model::ListObjectsV2Request request;
request.SetBucket(bucket);                
request.SetPrefix("");
request.SetMaxKeys(1000);

Aws::S3::Model::ListObjectsV2Outcome outcome = client.ListObjectsV2(request);

if (!outcome.IsSuccess())
{
    printf("Failed to list files from S3 because %s: %s\n",
           outcome.GetError().GetExceptionName().c_str(),
           outcome.GetError().GetMessage().c_str());
    printf("\n\n\n\n");
    assert(false);
}

printf("num keys returned %d\n", outcome.GetResult().GetKeyCount());

for (const Aws::S3::Model::Object& obj : outcome.GetResult().GetContents())
{
    printf("Callback %s", obj.GetKey().c_str());
}

Aws::Utils::Logging::ShutdownAWSLogging();

exit(0);

我正在使用 minio 作为我的对象存储,但是对于 amazon s3 它工作正常

查看 http 请求的差异并阅读代码,看起来您需要在 S3Client 中将 m_useVirtualAddressing 设置为 true。

好吧……谁知道呢。

我的客户说

   client = Aws::S3::S3Client(credentials, config, Aws::Client::AWSAuthV4Signer::PayloadSigningPolicy::Never, false);