I'm trying to use an image from a AWS S3 bucket as a texture in three.js. I get the following error -
Access to Image at 'https://s3-a...' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
I have set my CORS settings so there is no issue viewing the images in an tag. Following Three.js threads I've also tried using
myImage.crossOrigin = "anonymous"
myImage.crossOrigin = ""
THREE.ImageUtils.crossOrigin = ""
THREE.ImageUtils.crossOrigin = "anonymous"
Update: CORS settings on s3 bucket are as follows -
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedOrigin>http://*</AllowedOrigin>
<AllowedOrigin>https://*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
curl -i -H "Origin: http://localhost:3000/" https://s3-a/path-to-image
. If you don’t see anAccess-Control-Allow-Origin
header in the response from that then CORS is not configured correctly on the server. – sideshowbarkerlocalhost
? I don't think it does. Try updating the cors config and usinghttp://lvh.me:3000
to access your test site. The lvh.me hostname is a test that is equivalent to "localhost." You can also use www.127.0.0.1.xip.io:3000, and there are probably others. – Michael - sqlbothttp://
URL for the image instead of anhttps://
URL? If you remove the<AllowedOrigin>http://*</AllowedOrigin>
and<AllowedOrigin>https://*</AllowedOrigin>
lines from your CORS config XML document does that change anything? – sideshowbarker