1

I wrote a simple file server in NodeJS to serve a HTML page with a Save To Drive button. HTML page is served at my_address:1337 and file to be saved is served at my_address:1338. Upon clicking the Save To Drive button, it shows "Starting Download" for a long time then displays Failed Download. XHR Error.

I thought this was due to the fact that the file was being served from a different port so I decided to do the same with an appengine app. Page served at http://sayodrive.appspot.com/index.html and file served at http://sayodrive.appspot.com/drivefile.jsp, I got the same problem.

Then I decided to do a local Java web application: same problem. Then I tried changing the content disposition to attachment (to force a download) but didn't work either.

Frustrated, I started Googling and came across this page that claims the Save To Drive button doesn't actually work. So I went back to the official Google Drive SDK page and discovered that their example button doesn't work too. Is this a bad dream?

SOURCE: index.html

<html>
  <head>
    <title>Test: Save To Drive</title>
    <!--  -->
    <link rel="canonical" href="http://sayodrive.appspot.com">
    <script src="https://apis.google.com/js/plusone.js"></script>
  </head>
  <body>
    <p>This must be the worst HTML you have ever seen :)</p>
    <div class="g-savetodrive"
       data-src="//http://sayodrive.appspot.com/drivefile.jsp"
       data-filename="Test Drive"
       data-sitename="Sayo Saves">
    </div>
  </body>
</html>

SOURCE: drivefile.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>DriveFile</title>
  </head>
  <body>
    <%
      java.io.Writer w = response.getWriter();
      response.setContentType("text/plain");
      w.write("If you're reading this in Drive, congrats!");
      w.flush();
      w.close();
    %>
  </body>
</html>
Sayo Oladeji
  • 741
  • 4
  • 15
  • 28

1 Answers1

0

The original sample was not working because the Cache-Control header was not being exposed by the server. This is now fixed.

Access-Control-Expose-Headers: Cache-Control, Content-Encoding, Content-Range

More in the documentation.

Ali Afshar
  • 40,967
  • 12
  • 95
  • 109