简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM