exportLink没有'Access

编程入门 行业动态 更新时间:2024-10-28 18:33:35
本文介绍了exportLink没有'Access-Control-Allow-Origin'标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个基本的JavaScript代码段,用于从谷歌驱动器下载公共共享文件。我创建了一个API密钥,并将我的域配置为允许的引用列表。按照此处 https://开发人员所述,尝试打开exportLink时,我会遇到典型的CORS错误。 google/drive/web/manage-downloads 。在浏览器中访问时,下载链接正常工作。

I have a basic javascript snippet to download a publically shared file from google drive. I created an API key and configured my domain to be on the list of allowed referrers. I get the typical CORS error when trying to open the exportLink as described here developers.google/drive/web/manage-downloads. The download link works just fine when accessed in the browser.

错误:

Error:

No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'www.example' is therefore not allowed access.

代码:

Code:

// setup api key gapi.client.setApiKey('myKey'); // load libraries and get file from drive API ... // download file var xhr = new XMLHttpRequest(); xhr.open('GET', file['exportLinks']['text/csv']); xhr.onload = function() { callback(xhr.responseText); }; xhr.onerror = function() { callback(null); }; xhr.send();

推荐答案

我已经确认这是Drive API,但它只影响新Google表格文件的导出链接。旧的Google表格和其他Google文件类型应正常工作。我已经向团队提出了这个问题,但尚不清楚需要多长时间才能解决问题。不幸的是,没有简单的解决方法,唯一的解决方案是引入一个服务器端组件,它可以下载文件,然后将它传递给客户端。

I've confirmed that this is a bug in the Drive API, but it is only affecting the exportLinks for New Google Sheets file. Old Google Sheets and other Google file types should work correctly. I've raised it with the team, but it's unclear how long it will take to fix. Unfortunately there are no simple workarounds, and the only solution would be to introduce a server-side component that would download the file and then pass it along to the client.

更多推荐

exportLink没有'Access

本文发布于:2023-11-24 19:10:58,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:exportLink   Access

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!