Drafts Script Reference
    Preparing search index...

    Class 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.

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

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

    // write to file on Dropbox
    let 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();
    }
    Index

    Constructors

    • Create new instance.

      Parameters

      • Optionalidentifier: string

      Returns Dropbox

    Properties

    lastError: string

    If a function fails, this property will contain the last error as a string message, otherwise it will be undefined.

    Methods

    • Execute a request against the Dropbox API for an endpoint of Content Download type. For successful requests, the HTTPResponse object will contain an raw data in the responseData property and, if the data can be converted to a string value, the text version in the responseText property. The HTTPResponse otherData property will contain a Javascript object decoded from the JSON returned in the Dropbox-API-Result header. Refer to Dropbox's API documentation for details about the expected parameters and responses. Drafts will handle wrapping the request in the appropriate OAuth authentication flow.

      Parameters

      Returns HTTPResponse

    • Execute a request against the Dropbox API for an endpoint of Content Upload type. For successful requests, the HTTPResponse object will contain an object or array or objects decoded from the JSON returned by Dropbox as appropriate to the request made. Refer to Dropbox's API documentation for details about the expected parameters and responses. Drafts will handle wrapping the request in the appropriate OAuth authentication flow.

      Parameters

      Returns HTTPResponse

    • Reads the contents of the file at the with the file name, in the parent folder, as a string. Returns undefined value if the file does not exist or could not be read.

      Parameters

      • path: string

        Path related to root of Dropbox folder.

      Returns string

    • Execute a request against the Dropbox API for an endpoint of RPC type. For successful requests, the HTTPResponse object will contain an object or array or objects decoded from the JSON returned by Dropbox as appropriate to the request made. Refer to Dropbox's API documentation for details about the expected parameters and responses. Drafts will handle wrapping the request in the appropriate OAuth authentication flow.

      Parameters

      Returns HTTPResponse

    • Write the contents of the file at the path. Returns true if successful, false if the file could not be written successfully. This will override existing files!

      Parameters

      • path: string

        Path related to root of Dropbox folder.

      • content: string

        Text to write to file.

      • mode: dropboxMode

        Either "add" or "overwrite" to determine if the write method should overwrite an existing file at the path if it exists.

      • autorename: boolean

      Returns boolean

    • Creates a new Dropbox object.

      Parameters

      • Optionalidentifier: string

        used to identify a Dropbox account. Typically this can be omitted if you only work with one Dropbox account in Drafts.

      Returns Dropbox