首页 > 解决方案 > 尝试从谷歌驱动器加载 gltf 模型时出现 CORS 错误

问题描述

我目前正在尝试从 Google Drive 将 gltf 模型加载到我的 Aframe 场景中,如下所示:

<a-entity gltf-model="url(https://drive.google.com/uc?export=view&id={redacted})"></a-entity>

但我收到以下错误:

Access to XMLHttpRequest at 'https://drive.google.com/uc?export=view&id={redacted}' from origin 'http://localhost:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我正在使用配置为允许来自此处的 CORS 的 python SimpleHTTPServer:https ://gist.github.com/mkows/cd2122f427ea722bf41aa169ef7​​62001

当我将图像上传到谷歌驱动器并尝试使用 <img src="https://drive.google.com/uc?export=view&id={redacted}" />图像加载时加载正常。

有什么问题?

标签: htmlthree.jsgoogle-drive-apicorsaframe

解决方案


我正在使用配置为允许 CORS 的 python SimpleHTTPServer

不是为了这个。

该请求由负责的服务器提供服务drive.google.com,而不是localhost:8000

您已将 CORS 标头应用于错误的服务器。


由于您不控制 Google Drive 的响应标头,请考虑将文件托管在其他地方(或通过您自己的服务器代理它,这实际上是同一件事)。


推荐阅读