Let's upload a text file to Dropbox in Node.js

Here we'll show you how to use our Node.js SDK to upload a file to Dropbox.

Set up with Temboo and Dropbox

1 Log in to Temboo. If you don't already have an account, you can register for free.

2Make sure you've downloaded the Temboo Node.js SDK and that you've installed it as described in our Node.js getting started tutorial.

3You'll also need a valid Dropbox account and a Dropbox app, which you can create in the Dropbox App Console. The app name and domain can be whatever you like. Make sure to use the settings shown in the screenshot below when creating your new Dropbox app:

The Dropbox app console with the app settings you need for this example

The Dropbox app console with the app settings you need for this example

4With your Dropbox application in place, visit the Dropbox OAuth bundle. Starting with the InitializeOAuth Choreo, use these Choreos to grant your Dropbox application access to interact with Dropbox on your behalf. This short video demonstrates how to use our OAuth Choreos, and it's a good idea to take a break and watch it now before you dive into this step. You'll need the access tokens returned by this process to complete the rest of this tutorial.

5 Go to the Dropbox > FilesAndMetadata > UploadFile Choreo in our Library. Enter your Dropbox access tokens and click on the Save Profile button to save your Dropbox app details. Make sure to fill in "sandbox" for Root input. Now you can reuse these Dropbox authentication details on any Dropbox Choreo in our Library. Using a Profile will also make your code simpler and more secure.

Test the Choreo

6 Go to the Dropbox > FilesAndMetadata > UploadFile Choreo page. Select Node.js from the drop down menu at the top of the page. Start by inserting your Dropbox account info that you saved earlier. Next, enter a FileName (like "test.txt") and finally put something into the FileContents input (like "Hello World!").

You could also use the FileContentsFromURL input to pass a hosted file or image to Dropbox.

7 Click Generate Code to test the Choreo from our website, and you'll see some details about your uploaded file in the Output section. If you go to your app folder in Dropbox, you'll see your file appear!

Base64 Encoding (or "Help! I can't read the text")

8 If you open your uploaded file, you'll see some garbled text. That's because the Dropbox UploadFile Choreo needs a Base64 encoded string for its FileContents input. Luckily enough we have one of these Choreos in our Temboo Library. Go to the Utilities > Encoding > Base64Encode Choreo to get started.

9 Type "Hello world" into the Text input and click Generate Code. You should see a Base64 translation appear in the output. If you pass this text to the Dropbox Choreo it will create the file in Dropbox with human-readable text as expected.

Combining Choreos

10 To finish this example up, let's combine the two Choreos in one Node.js script. In the code block below, we've called both the Dropbox Choreo and the Base64 Encode Choreo. We've added a time stamp on the file name to allow multiple uploads (otherwise the upload will overwrite an earlier file of the same name).

To use the code below, simply substitute in your Dropbox Profile name and then run the code. Your new upload should appear in your Dropbox folder with the value of the "temboo_(current date + time).txt".

var Session = require("temboo/core/temboosession");
var Utilities = require("temboo/Library/Utilities/Encoding");
var Dropbox = require("temboo/Library/Dropbox/FilesAndMetadata");

var session = new Session.TembooSession("ACCOUNT_NAME", "APP_NAME", "APP_KEY");

// Set up the encoding choreo.
var base64EncodeChoreo = new Utilities.Base64Encode(session);
// Instantiate and populate the input set for the choreo
var base64EncodeInputs = base64EncodeChoreo.newInputSet();
// Set the file's contents.
base64EncodeInputs.set_Text("You just made this file with Temboo's Node.js SDK!");

// Execute the choreo to base64 encode your text.
// If the choreo succeeds, the upload function will be triggered as a callback.
    function(results) {
    function(error) {

// Function to call on encode success to upload file to Dropbox.
function uploadEncodedFile(fileContents) {
    var uploadFileChoreo = new Dropbox.UploadFile(session);
    var dateString = new Date().toISOString().replace(/\..+/, '');
    var fileName = ["temboo_", dateString, ".txt"].join("");

    // Instantiate and populate the input set for the choreo
    var uploadFileInputs = uploadFileChoreo.newInputSet();
    // Set to the name of the Profile you created earlier in the tutorial

    // Set inputs.

    // Run the choreo, specifying success and error callback handlers.
        function(error) {

What next?

We're all finished! This Node.js application can create a text file out of any string you might produce while coding. Try using it to save all sorts of different content, like the data return by any of the 2000+ Choreos in our Library.

Once you've got your code up and running, you're ready to move on and do more. From monitoring your running applications, to moving your generated Temboo code to your preferred development environment and sharing it with colleagues, collaborators and friends - we've got you covered.

Get Live Updates About Your Application

Integrate Temboo with Slack to get up-to-the-second notifications and alerts about your deployed Temboo code.

Commit Code to GitHub

Commit Temboo-generated code directly to GitHub and share with the world. Learn more.

Need help?

We're always happy to help. Just email us at support@temboo.com, and we'll answer your questions.