0

As per spec, Google Docs can be downloaded in different formats using the appropriate exportLinks entry in the file metadata obtained using the Drive API. The URLs specified by these entries support CORS, so one can use them from pure Javascript, without a proxy.

This works for most files and document types (doc, presentation) but not spreadsheets. When you try an XHR GET on a spreadsheet exportLinks URL from browser Javascript,

  1. The OPTIONS request returns a valid response, but it has an Expires header of Fri, 01 Jan 1990 00:00:00 GMT
  2. The browser gives up at this point (probably due to the Expires)
  3. Doing a GET with the same Authorization, Referer, Origin headers using curl returns the spreadsheet alright, but the response headers don't contain any Access-Control-Allow-Origin header, so it wouldn't have worked from the browser.

Other document types behave in the expected manner for OPTIONS and GET, returning correct Expires and CORS headers.

In fact, old spreadsheets - those with exportLink URLs which look like https://docs.google.com/feeds/download/spreadsheets/Export?key=XXX&exportFormat=xlsx also work. The problem is confined to new sheets, whose exportLink URLs look like https://docs.google.com/spreadsheets/export?id=XXX&exportFormat=xlsx.

I hit this issue with pigshell using the following steps:

  1. Visit pigshell using a desktop browser (Chrome/Firefox/Safari)
  2. Attach a Google account by clicking on the Google icon in the rightbar
  3. In the pigshell CLI,

    cd /gdrive/<[email protected]>
    ls
    gcat <docfilename>                # Displays PDF version of doc
    gcat <spreadsheetfilename>        # CORS failure, examine browser console/devtools
    gcat <spreadsheetcreatedyearsago> # Works
    

1 Answer 1

1

This is essentially the same question that was asked here:

No 'Access-Control-Allow-Origin' header for exportLink

It seems to be a known bug when using the Drive API with the new version of Google Sheets (other Google file types and the older version of sheets don't seem to have the issue). Unfortunately, no known workarounds, except "to introduce a server-side component that would download the file and then pass it along to the client."

2
  • Thanks. Somehow missed that question. It's a shame that a simple straight-line failure has not been fixed in months, and what's more, doesn't even appear in the list of open issues.
    – ganeshv
    Feb 13, 2015 at 4:43
  • hey @ryanroth, do you know, has this issue been solved?
    – Slava32
    Jun 11, 2016 at 21:07

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.