"No 'Access-Control-Allow-Origin' header is present on the requested resource" - Unity WebGL AWS



在 AWS S3 上存储 Unity WebGL 项目并从另一个域检索它时,会给出 CORS 错误:

"XMLHttpRequest 无法加载。请求的资源上不存在'访问控制-允许源'标头">

此错误仅发生在 .unityweb 文件,.json 和 .js 文件工作正常。


这个问题的许多旧解决方案不再有效,但我发现一个较新的解决方案隐藏在一些评论中。我认为创建一个新问题并自己回答它会更容易,以防其他人需要它。

在 S3 存储桶中,转到权限,然后选择 CORS 配置。 将其粘贴到:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>

"HEAD"允许的方法很重要,它允许检索.unityweb文件。

相关内容

最新更新