Klick
Klick

Reputation: 1653

AWS S3 presign url, check file exist

I use AWS php SDK. How can I check if file exist using presign request commands?

Currently I use "GetObject" command but I do not need it download file. I only need check if file exist.

$cmd = $s3->getCommand('GetObject', [
        'Bucket' => 's3.test.bucket',
        'Key'    => $fileKey
    ]);

    $request = $s3->createPresignedRequest($cmd, '+60 minutes')->withMethod('GET');

    return (string)$request->getUri();

Is there any command to achieve it?

Thank you.

Upvotes: 0

Views: 544

Answers (1)

Klick
Klick

Reputation: 1653

I found solution. The proper command is HeadObject and method is HEAD. Return 200 or 404.

Upvotes: 1

Related Questions