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 the user tries to download a specific file, I need to check if the new standard naming URL exists, and if not, download it from the old standard URL.

Is there a way to "ping" an S3 URL to find out if the correct file is saved at the URL? Standard AJAX calls do not work due to problems between domains.

The files that I check are binary files.

+4
source share
1 answer

You can look at the headObject () method in the AWS JavaScript SDK, but if the file is public, just HEADrequest (using ajax).

You can resolve cross-domain issues by specifying the CORS policy in your bucket.

+1
source

All Articles