Drafts Script Reference

Dropbox

Dropbox objects can be used to work with files in a Dropbox account. The read and write methods are simple wrappers for uploading and reading content of files on Dropbox.

For advanced uses, the rpcRequest, contentUploadRequest and contentDownloadRequest methods enable direct use of any Dropbox API 2.0 endpoints. These methods are an advanced feature which return raw results from the Dropbox API and may require advanced understanding of the API to process the results. They do enable full access to the API, however, which enabled things like querying files, listing folder contents, uploading to Paper, etc. For details on availalbe methods, see Dropbox API documentation. In the case of all of these methods Drafts takes care of the OAuth request signing and authentication process when necessary.

Properties

Convenience Functions

Functions

Class Functions

Examples

// create Dropbox object
var db = Dropbox.create();

// setup variables
var path = "/test/file.txt";
var content = "text to place in file";

// write to file on Dropbox
var success = db.write(path, content, "add", true);

if (success) { // write worked!
  var dbContent = db.read(path);
  if (dbContent) { // read worked!
    if (dbContent == content) {
      alert("File contents match!");
    }
    else {
      console.log("File did not match");
      context.fail();
    }
  }
  else { // read failed, log error
    console.log(db.lastError);
    context.fail();
  }
}
else { // write failed, log error
  console.log(db.lastError);
  context.fail();
}