amazon web services – AWS c++ SDK S3 HeadObjectRequest returns empty metadata

I have an object in AWS S3 storage. I want to access the HeadObject metadata. From the cli:

aws s3api head-object –bucket equimed-com –key images/test.data

I get:

{
    "AcceptRanges": "bytes",
    "LastModified": "2025-01-01T15:26:44+00:00",
    "ContentLength": 256,
    "ETag": "\"6f7e1767f434392c90acf01e411511d9\"",
    "ContentType": "binary/octet-stream",
    "ServerSideEncryption": "AES256",
    "Metadata": {}
}

Nice!!

When I attempt to access this metadata using the c++ api, using this code:

Ris::Return_code Ris::status(const std::string& bucket, const std::string& path,
                             const std::string& key) {
  std::string filepath = path + "/" + key;
  Aws::String bckt(bucket.c_str(), bucket.length());
  Aws::String ky(filepath.c_str(), filepath.length());

  Aws::S3::Model::HeadObjectRequest request;
  request.SetBucket(bckt);
  request.SetKey(ky);

  auto outcome = Ris::s3Client.HeadObject(request);

  Ris::Return_code rc = Ris::Return_code::ok;
  if (!outcome.IsSuccess()) {
    if (outcome.GetError().GetErrorType() == Aws::S3::S3Errors::NO_SUCH_KEY) {
      rc = Ris::Return_code::image_not_found;
    } else {
      std::ostringstream out;
      out << "Ris::status() failed.\n";
      out << "Error HeadObject " << outcome.GetError().GetMessage() << "\n";
      throw std::runtime_error(out.str());
    }
  }

  std::cout << "Metadata: " << std::endl;
  Aws::Map<:string aws::string=""> metadata = outcome.GetResult().GetMetadata();
  for (const auto& pair : metadata) {
    std::cout << "Key: " << pair.first << " Value: " << pair.second << std::endl;
  }

  return rc;
}

I get an empty metadata map.

What gives?? Please help.

Note that the std::cout stuff is strictly for debugging purposes.

Read more here: Source link