7

If you want to allow users to save a file on your website to Google Drive, it's ridiculously simple. Just use the Save to Drive Button and in a few lines of code, everything is taken care of. Great.

I want exactly that behavior for my website. However, I want to save user-generated text there, rather than a static file sitting on my server. I have the text in a JavaScript variable, but it seems there's no way to use the easy Save to Drive Button with that. The documentation states that "Data URIs ... are not supported" and my testing indicates that object URLs are similarly unsupported (this guy found the same thing).

I am aware that, in theory, it should be possible to use the Google Drive API to do what I want. This question and this question provide some hints at how that might maybe work, but it all seems incredibly complicated (nobody has even made a demo showing that it actually works, AFAICT).

I don't want to have to deal with user logins, sessions, API keys, authorization, permissions, having users "install" my app within Google Drive, etc. I just want a button someone can press to store some text from a JS variable in a new document. Exactly how the Save to Drive Button works. Is this even remotely feasible?

It's not just about complexity on my end, it's about complexity for my users. I want to provide them a very simple, self contained functionality. I don't want my app to be deeply intertwined with Google Drive.

Community
  • 1
  • 1
dumbmatter
  • 9,351
  • 7
  • 41
  • 80
  • Can you save the data to a temporary file, and the use the Save to Drive button with that file? – dpk2442 Jun 14 '14 at 04:36
  • The whole reason for my desire to use Google Drive is to save me the trouble of building my own server-side storage system. My app is 100% client-side JS, but I want people to be able to export data easily. – dumbmatter Jun 14 '14 at 05:07
  • Fair enough. Could you make it a Chrome extension or something like that? – dpk2442 Jun 14 '14 at 05:08
  • I like having it as a web app that anyone on any device can access. But what would making it a Chrome extension enable? – dumbmatter Jun 14 '14 at 18:19
  • I could be wrong, but I'm pretty sure chrome apps at least can access the file system. It's possible extensions can too, but I don't know. – dpk2442 Jun 15 '14 at 21:30
  • For saving a file to disk, I use `createObjectURL` which allows you to create a downloadable file filled with content generated in client-side JS. It works even with huge amounts of data. However, saving files to disk does not provide a great user experience on mobile, which is why I got to thinking about Google Drive as an alternative. – dumbmatter Jun 16 '14 at 04:05
  • Can't you just use the URL from that with the Save to Drive button? – dpk2442 Jun 16 '14 at 13:46
  • Sadly not, it doesn't work with object URLs, data URIs, or file:// URLs, and I can't think of any other kind of fake URL to try. – dumbmatter Jun 17 '14 at 01:48

1 Answers1

2

Unfortunately this is not possible today. The Save to Drive button tries to simplify a common use case, but for more specialized use cases like your's you'll need to develop against the API directly.

Eric Koleda
  • 12,420
  • 1
  • 33
  • 51
  • That's about what I figured. I ended up basing my code on https://developers.google.com/drive/web/quickstart/quickstart-js which isn't completely horrible, but it's significantly more complicated than the Save to Drive button for both me and my users. – dumbmatter Jun 20 '14 at 02:38
  • 1
    And did you manage to save client side created data to google drive? Can you share your work if so? – Mike de Klerk Sep 20 '17 at 10:25