exportLink没有'Access-Control-Allow-Origin'标头 [英] No 'Access-Control-Allow-Origin' header for exportLink

查看:285
本文介绍了exportLink没有'Access-Control-Allow-Origin'标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本的JavaScript代码段,用于从谷歌驱动器下载公共共享文件。我创建了一个API密钥,并将我的域配置为允许的引用列表。按照此处 https://开发人员所述,尝试打开exportLink时,我会遇到典型的CORS错误。 google.com/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 https://developers.google.com/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 'http://www.example.com' 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-Control-Allow-Origin'标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆