I need to get retrieve some publicly accessible files from S3.
That's my S3 CORS configuration:
<?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>
And here's my JS code:
const response = await fetch(url, {
mode: 'cors',
});
const blob = await response.blob();
It works, but not always. Sometimes I have the following error in the console:
Access to XMLHttpRequest at 'https://my-bycketuel/file.jpg' from origin 'https://my.host' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
But after I reload the page (sometimes several times, sometimes just once) then the error is gone and I'm able to read the response object.