Upload a text file to Dropbox

Here we'll show you how to upload a text string as a file Dropbox, using the Dropbox API.

Set up with Temboo and Dropbox

1 First you'll need a valid Dropbox account and a Dropbox app, which you can create here. 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

2 With 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.

3 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

4 Let's test the Dropbox > FilesAndMetadata > UploadFile Choreo directly from the Temboo Library. If they aren't already there, insert your Profile values. Next enter a FileName (like "test.txt"). And finally put something into the FileContents input (like "Hello world").

(NOTE: You could alternatively use the FileContentsFromURL input to pass an entire website or an image to Dropbox.)

5 Click Run and if there are no errors, you'll see some details about your upload in the Output section. And if you go to your app folder in Dropbox, you'll see your file appear!

6 Now, copy the generated Code directly into your Processing sketch and try running it there.

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

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

8 Type "Hello world" into the Text input and click Run. You should see a Base64 translation appear in the output.

9 Now, copy the generated Code directly into a new Processing sketch. Run it there, and you should see the same results.

Two Choreos in a sketch

10 To finish things up, let's combine these two Choreos in one sketch. We're putting both Choreos functions in the same sketch and making sure that all necessary import statements are included. The only other things we're adding are some global variables for the file name and contents. We've also added a time stamp on the file name to allow multiple uploads (otherwise the upload will overwrite an earlier file of the same name).

Update your Temboo account details and Dropbox Profile name in the sketch below and run it. Your new upload should appear in your Dropbox folder with the fileContents string as its text.

import com.temboo.core.*;
import com.temboo.Library.Dropbox.FilesAndMetadata.*;
import com.temboo.Library.Utilities.Encoding.*;

// Create a session using your Temboo account application details
TembooSession session = new TembooSession("ACCOUNT_NAME", "APP_NAME", "APP_KEY");

// The name of your Temboo Dropbox Profile 
String dropboxProfile = "yourDropboxProfile";

// Declare file name and content strings
String fileName, fileContents, b64FileContents;

void setup() {
  // Set file name and contents
  String timeStamp = "_"+year()+month()+day()+"_"+hour()+minute()+second();
  fileName = "temboo"+timeStamp+".txt";
  fileContents = "You just made this file with Processing and Temboo! (Now you can put something more awesome here.)";

  // Base64 encode a string and upload it to Dropbox

void draw() {

void runBase64EncodeChoreo() {
  // Create the Choreo object using your Temboo session
  Base64Encode base64EncodeChoreo = new Base64Encode(session);

  // Set inputs

  // Run the Choreo and store the results
  Base64EncodeResultSet base64EncodeResults = base64EncodeChoreo.run();

  // Set base64FileContents
  b64FileContents = base64EncodeResults.getBase64EncodedText();
  println(fileName+" has been Base64 encoded...");

void runUploadFileChoreo() {
  // Create the Choreo object using your Temboo session
  UploadFile uploadFileChoreo = new UploadFile(session);

  // Set Profeil

  // Set inputs

  // Run the Choreo and store the results
  UploadFileResultSet uploadFileResults = uploadFileChoreo.run();
  println("and uploaded to Dropbox!");

What next?

We're all finished! This sketch can create a text file out of any string you might produce while coding. Try using it to save all sorts of different content. And check out our Library for some more ideas.

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.