My current objective is to access publicly available files stored in S3.
The CORS configuration for my S3 setup is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
My JavaScript code implementation looks like this:
const response = await fetch(url, {
mode: 'cors',
});
const blob = await response.blob();
The code works most of the time, however, I encounter an error in the console occasionally:
Access to XMLHttpRequest at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Interestingly, after refreshing the page a few times, or sometimes just once, the error disappears and I can successfully retrieve the response object.