1

I use the S3 SDK CPP and have the following cenario:

  1. I get some information sent from a client to my server (client wants to download from S3)
  2. With the information sent I create a S3 key
  3. I want to check if the key exists (has a file) on the S3
  4. I create a presigned URL that allows the client to download a file from S3
  5. Send URL to client
  6. Client downloads the file

Before I execute step 4 I want to check if the key really exists on the S3. The client can't download a file that does not exist anyway.

I have an AWS::S3Client object. Do I really need to create a TransferManager for this or is there a simple way to handle this with the client object?

The client itself does not have a relation to S3 so I can't check it there. The server has to do all the work.

Mikhail Zhuikov
  • 1,213
  • 2
  • 9
  • 19
Michael Kemmerzell
  • 4,802
  • 4
  • 27
  • 43

2 Answers2

3

I found a working solution:

auto client = Aws::MakeShared<Aws::S3::S3Client>("client", getCredentials(), getClientConfig());
Aws::S3::Model::HeadObjectRequest request;
request.WithBucket(<bucketname>).WithKey(<s3key>);
const auto response = client->HeadObject(request);
response.IsSuccess(); //Is key existing on s3?
Michael Kemmerzell
  • 4,802
  • 4
  • 27
  • 43
1

Issue an authenticated HTTP HEAD request against the object. You can use:

To quote:

The HEAD operation retrieves metadata from an object without returning the object itself. This operation is useful if you're only interested in an object's metadata. To use HEAD, you must have READ access to the object.

jarmod
  • 71,565
  • 16
  • 115
  • 122