Skip to content

S3Client::DeleteObjects API fails with missing Content-MD5 error #1337

Closed

Description

@satyamshekhar

What platform/OS are you using?

Ubuntu

Which version of the SDK?

1.7.276

What compiler are you using? what version?

GCC 9.2

What are your CMake arguments?

-DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCPP_STANDARD=17 -DFORCE_SHARED_CRT=OFF -DENABLE_TESTING=OFF

Can you provide a TRACE level log? (sanitize any sensitive information)

aws_sdk_2020-03-05-06.log

The DeleteObjects fails with "Missing required header for this request: Content-MD5". I can see in the logs that the Content-MD5 header is not populated. I would have expected that to be set by the client library.

common::Status S3Client::DeleteObjects(
  const std::string& bucket_name,
  const std::set<std::string>& keys) {
  Aws::S3::Model::DeleteObjectsRequest request;
  request.WithBucket(bucket_name);
  Aws::S3::Model::Delete batch;
  for (const auto& key : keys) {
    Aws::S3::Model::ObjectIdentifier id;
    id.SetKey(key);
    batch.AddObjects(id);
  }
  request.SetDelete(std::move(batch));
  auto outcome = client_->DeleteObjects(request);
  if (not outcome.IsSuccess()) {
    auto err = outcome.GetError();
    return common::Status(S3ErrorToStatusCode(err), err.GetMessage());
  }
  return common::Status::OK;
}

Activity

  1. KaibaLopez commented on Mar 5, 2020

    @KaibaLopez
    Contributor

    Hi @satyamshekhar ,
    I'm not able to replicate this issue, using your sample code I was able to delete objects from my s3 bucket.
    Is there any other steps you might know of that makes your case special? Things like permissions, maybe special values in your s3 objects/buckets, or something of the sort?

  2. added
    response-requested
    on Mar 5, 2020
  3. satyamshekhar commented on Mar 5, 2020

    @satyamshekhar
    Author

    Nothing that I can think of. Does the value in the bucket matter? It is hard to imagine why the client would not send the "Content-MD5" based on bucket setting?

  4. KaibaLopez commented on Mar 5, 2020

    @KaibaLopez
    Contributor

    It shouldn't but I can't see anything weird in the sample code you provided that would be causing this error, so I'm assuming this is either due to some bucket or client configuration, permissions or object size.
    Couple things I'd like you to try,

    • Change std::set<std:string> to std::set<Aws::string>
    • In your logs it looks like you're doing some uploads, can you try just testing out the delete and see if you still get the same error?
  5. satyamshekhar commented on Mar 6, 2020

    @satyamshekhar
    Author

    The client exhibits this behavior when the number of objects to be deleted in |Delete| is zero. The error message is misleading. The client should either return early in such a case or still send a valid request with Content-MD5 to the server.

    I have fixed the problem locally by checking if the number of objects to deleted is 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    response-requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions