Check if File Exists on Amazon s3 Signed URL


I have create a signed $URL for Amazon s3 and it opens perfectly in the browser.

**Bucket name and accesskey changed in this example

I am however trying to then use the function below to check (using curl) that the file exists. It fails the CURL connection. If I replace $URL above with the url of an image outside of s3 then this code works perfectly.

I know the file exists in amazon but can’t work out why this code fails if using a signed url as above

Any ideas?


Here is my code.


When using CURLOPT_NOBODY, libcurl sends an HTTP HEAD request, not a GET request.

…the string to be signed is formed by appending the REST verb, content-md5 value, content-type value, expires parameter value, canonicalized x-amz headers (see recipe below), and the resource; all separated by newlines.

The “REST verb” — e.g., GET vs HEAD — must be consistent between the signature you generate, and the request that make, so a signature that is valid for GET will not be valid for HEAD and vice versa.

You will need to sign a HEAD request instead of a GET request in order to validate a file in this way.

Leave a Reply