html - 尝试从谷歌驱动器加载 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/cd2122f427ea722bf41aa169ef762001
当我将图像上传到谷歌驱动器并尝试使用
<img src="https://drive.google.com/uc?export=view&id={redacted}" />
图像加载时加载正常。
有什么问题?
解决方案
我正在使用配置为允许 CORS 的 python SimpleHTTPServer
不是为了这个。
该请求由负责的服务器提供服务drive.google.com
,而不是localhost:8000
。
您已将 CORS 标头应用于错误的服务器。
由于您不控制 Google Drive 的响应标头,请考虑将文件托管在其他地方(或通过您自己的服务器代理它,这实际上是同一件事)。
推荐阅读
- c# - 以 application/x-www-form-urlencoded 格式从邮递员发送数据到 Web API 控制器
- javascript - Preventing JQuery default behavior in Angular 11 app
- java - 如何跟踪两个依赖 LinkedLists 之间的出现次数?
- php - 如何在 cakephp 中将 HTML 内容转换为字符串?
- node.js - 在 Typescript 中更新导入的模块
- android - 在 EditText 中使用 Android LiveData 进行操作?
- solidity - 尝试在 nodejs 中使用 web3 和 ethersjs 进行煎饼交换交易时,交易一直失败
- arrays - 从多维结构中获取数据
- .net-5 - 为什么 .NET 5 中的引用类型没有 Interlocked.Read?
- html - 如何将 Bootstrap 4 列高限制为另一个列高?