Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if File Exists on AWS S3 Using Browser JavaScript SDK?

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.

like image 721
Lloyd Banks Avatar asked Sep 22 '14 21:09

Lloyd Banks


1 Answers

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.

like image 148
dcro Avatar answered Nov 14 '22 20:11

dcro