我有一个基本的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
发布评论