6

I recently changed the naming convention for a file in my job folders. Since I need to support both the new naming convention and the old naming convention when a user tries to download the specific file, I need to check if the new naming standard URL exists and if not, download from the old naming standard URL.

Is there a way to 'ping' a S3 URL to see if a valid file is stored at the URL? Standard AJAX calls doesn't work because of cross-domain issues.

The files I am checking for are binary files.

Lloyd Banks
  • 35,740
  • 58
  • 156
  • 248

1 Answers1

2

You can have a look at the headObject() method in the AWS JavaScript SDK, but if the file is publicly accessible, a simple HEAD request (using ajax) will also do.

You can work out the cross domain issues by specifying a CORS policy on your bucket.

dcro
  • 13,294
  • 4
  • 66
  • 75
  • How do you check a specific file using headObject()? With the parameters exposed, it seems you can only check for specific buckets. Also, I noticed that I do have CORS enabled. I just need to find a way to handle 403 responses from the server if the file doesn't exist – Lloyd Banks Sep 27 '14 at 13:01
  • With `headObject()` you need to specify both the bucket and the key (the file's full path inside the bucket). – dcro Sep 27 '14 at 18:02
  • If using CORS to check for HEAD, you need to make sure to include the HEAD method in your CORS policy. (Most default policies don't include it) HEAD – Matt Jul 08 '15 at 17:57