Question

I'm building a single-page web app that is meant to help writers finish their writing. I call it "Just Write, Dammit!" (https://www.justwritedammit.com). It emphasizes getting into writing flow and blocking out distractions.

One potential feature was to automatically save data for the user and sync that data across multiple computer/browser combinations and sessions. The user would choose their storage provider, i.e. Dropbox, Google Drive, or Microsoft OneDrive, do the whole OAuth dance, and make everything run directly through the browser and the provider, never even having to touch my server. Currently, the app has no server component. My hope was to minimize my hosting costs while I built the minimal product. Eventually, I will probably need a server, but for now I'd like to keep this on the client side as much as possible.

I haven't gotten around to Google Drive yet--so judgement reserved there--but as far as I can tell, despite surface promises of providing APIs to access file data, neither Dropbox nor[1] OneDrive actually does not. They provide access to metadata, and they let you initiate the download to the local file system for the user, but neither of them let you actually download the file into the browser.

Dropbox has a Datastore API that let's you store per-user information over the Web, but it doesn't generate a physical file for the user and there is no clean way to present that data to the user outside of the application context. I use this feature to provide a cross-browser/computer session sync, but to provide the user with a physical file I've had to implement a system using Data URIs to download a file out of the browser, which very definitely cannot be automated.

So my question is: have I missed something? Is this possible and I just haven't spent enough time on it? Is it possible with Google Drive or should I not waste my time?

[1] EDIT: as smarx points out, this is possible as I want it to be with Dropbox. The Datastore API's Client class has methods readFile and writeFile that do exactly what I want. The question still remains whether or not Google Drive and Microsoft OneDrive have similar functionality, however.

Was it helpful?

Solution

Dropbox's full web API can be used from JavaScript in the browser (including saving and loading files). See https://www.dropbox.com/developers/core/docs for the full API documentation.

Dropbox.js is your best bet for a JavaScript SDK for the Dropbox API: https://github.com/dropbox/dropbox-js.

The Datastore API SDK (which you already found) also includes methods for accessing files. It's basically a fork of dropbox.js, but for pure file manipulation, I'd stick with the open-source dropbox.js.

Here's a blog post I wrote a little while ago that shows you how to authenticate a user and write a file to that user's Dropbox: https://www.dropbox.com/developers/blog/71/writing-a-file-with-the-dropbox-javascript-sdk.

Short version of the code pasted below for convenience, but check out the blog post for a more realistic example.

var client = new Dropbox.Client({ key: 'YOUR-APP-KEY-HERE' });
client.authenticate(function () {
    client.writeFile('hello.txt', 'Hello, World!', function () {
        alert('File written!');
    });
});

OTHER TIPS

It sounds like you want the Drive Realtime API: https://developers.google.com/drive/realtime/

It automatically saves content as its typed, handles conflicts between multiple simultaneous sessions, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top