删除对象

使用 deleteObject 接口删除某一个桶中的对象。

以下代码展示如何删除某一个桶中的对象:

bool S3Demo::DeleteObject()
{
  const Aws::String object_name = "ExampleObject.txt";

  Aws::S3::Model::DeleteObjectRequest request;
  request.SetBucket(s3_bucket_name);
  request.SetKey(object_name);

  Aws::S3::Model::DeleteObjectOutcome outcome = s3_client->DeleteObject(request);
  if (outcome.IsSuccess()) {
    std::cout << "DeleteObject " << object_name << " success";
    return true;
  }
  else {
    Aws::S3::S3Error err = outcome.GetError();
    std::cout << "Error: DeleteObject: " << (int)err.GetResponseCode() << ", Message:" <<
      err.GetMessage() << std::endl;
    return false;
  }
}