我试图使用AWS S3存储桶中的图像作为three.js中的纹理。我碰到下面的错误 - 从起源 “http://localhost:3000”Three.js AWS S3 CORS
访问图片在“https://s3-a ...”已被封锁通过CORS政策:否 “访问控制允许来源”标头出现在请求的 资源。原因'http://localhost:3000'因此不允许 访问。
我已经设置了我的CORS设置,因此查看标签中的图像没有问题。继three.js所线程我也尝试使用
myImage.crossOrigin = "anonymous"
myImage.crossOrigin = ""
THREE.ImageUtils.crossOrigin = ""
THREE.ImageUtils.crossOrigin = "anonymous"
更新:是对S3存储 CORS设置如下 -
<CORSConfiguration>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedOrigin>http://*</AllowedOrigin>
<AllowedOrigin>https://*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
能够使用img标签加载图像并不意味着您已在服务器上正确设置CORS。没有CORS,跨源img元素可以正常工作。 – sideshowbarker
尝试使用curl或其他方法来请求图像并检查响应标题。例如,'curl -i -H“Origin:http:// localhost:3000 /”https:// s3 -a/path-to-image'。如果在响应中没有看到“Access-Control-Allow-Origin”标头,则服务器上的CORS配置不正确。 – sideshowbarker
CORS是否使用主机名'localhost'?我不认为它确实如此。尝试更新Cors配置并使用'http://lvh.me:3000'访问您的测试站点。 lvh.me主机名是一个等同于“localhost”的测试。您也可以使用www.127.0.0.1.xip.io:3000,并且可能还有其他的。 –