Let's upload a text file to Dropbox

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

Get Set Up

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

2Download the Temboo Android SDK and add it to your development environment. Confirm that your project has <uses-permission android:name="android.permission.INTERNET"/> in its manifest. Clear the text in the generated TextArea, and set its id to @+id/result. If you need help with any of these steps, please refer to our getting started tutorial, but copy and import the Dropbox-1.76.jar and Utilities-1.76.jar instead of the Google-1.76.jar.

3You'll also 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

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 Let's test the Dropbox > FilesAndMetadata > UploadFile Choreo directly from our website. Start by inserting your Dropbox account info by clicking on the Insert Credential button. Next, enter a FileName (like "test.txt") and finally put something into the FileContents input (like "Hello World!").

7 Click Run 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!

8 Now, copy the generated Code directly into the doInBackground method of your AsyncTask class. Remember to import the required classes. Finally, deploy and run your app.

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

9 If you open your uploaded file in Dropbox, 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.

10 Type "Hello world" into the Text input and click Run. 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

11 To finish this example up, let's combine the two Choreos in one Android class. In the code block below, we've called both the Dropbox Choreo and the Base64 Encode Choreo from the doInBackground method. We've added some constants for the file name and contents, and a timestamp on the file name to allow multiple uploads (otherwise the most recent upload will overwrite the previous file of the same name).

To use the code below, simply substitute in your Dropbox Credential name and your Temboo account details and deploy/run your app. Your new upload should appear in your Dropbox folder with the value of the FILE_CONTENTS variable as its text.

package com.temboo.android.gettingstarted.app;

import android.os.AsyncTask;
import android.util.Log;
import android.widget.TextView;

import com.temboo.Library.Dropbox.FilesAndMetadata.UploadFile;
import com.temboo.Library.Dropbox.FilesAndMetadata.UploadFile.UploadFileInputSet;
import com.temboo.Library.Dropbox.FilesAndMetadata.UploadFile.UploadFileResultSet;
import com.temboo.Library.Utilities.Encoding.Base64Encode;
import com.temboo.Library.Utilities.Encoding.Base64Encode.Base64EncodeInputSet;
import com.temboo.Library.Utilities.Encoding.Base64Encode.Base64EncodeResultSet;
import com.temboo.core.TembooSession;

import java.text.SimpleDateFormat;
import java.util.Date;

 * An AsyncTask that will be used to encode a string and upload it as a file to DropBox
class DropboxTask extends AsyncTask<Void, Void, String> {

    private TextView textView;

    // The name of your Temboo Dropbox credential.

    // Set file name and contents.
    // Note the date and file extension are being added to the file name in the Dropbox input set.
    private static final String FILE_NAME = "hello"; 
    private static final String FILE_CONTENTS = "You just made this file with Java and Temboo! ";

    public DropboxTask(TextView textView){
        this.textView = textView;

    protected String doInBackground(Void... arg0) {
        try {
            // Instantiate the Choreo, using a previously instantiated TembooSession object, eg:
            TembooSession session = new TembooSession("ACCOUNT_NAME", "APP_NAME", "APP_KEY");

            // Instantiate the Utilities.Encoding.Base64Encode Choreo, using the session object.
            Base64Encode base64EncodeChoreo = new Base64Encode(session);

            // Get an InputSet object for Utilities.Encoding.Base64Encode Choreo.
            Base64EncodeInputSet base64EncodeInputs = base64EncodeChoreo.newInputSet();

            // Set inputs for Utilities.Encoding.Base64Encode Choreo.

            // Execute Utilities.Encoding.Base64Encode Choreo.
            Base64EncodeResultSet base64EncodeResults = base64EncodeChoreo.execute(base64EncodeInputs);

            // Generate and format a timestamp that we can put at the end of the file name.
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
            String formattedDate = sdf.format(date);

            // Instantiate the Dropbox.FilesAndMetadata.UploadFile Choreo, using the session object.
            UploadFile uploadFileChoreo = new UploadFile(session);

            // Get an InputSet object for Dropbox.FilesAndMetadata.UploadFile Choreo.
            UploadFileInputSet uploadFileInputs = uploadFileChoreo.newInputSet();

            // Set Dropbox credentials.

            // Set inputs for Dropbox.FilesAndMetadata.UploadFile Choreo.
            uploadFileInputs.set_FileName(FILE_NAME + "_" + formattedDate + ".txt");

            // Execute Dropbox.FilesAndMetadata.UploadFile Choreo.
            UploadFileResultSet uploadFileResults = uploadFileChoreo.execute(uploadFileInputs);

            return "File upload success: " + uploadFileResults.get_Response();
        } catch(Exception e) {
            // if an exception occurred, log it
            Log.e(this.getClass().toString(), e.getMessage());
        return null;

    protected void onPostExecute(String result) {
        try {
            // Update UI
        } catch(Exception e) {
            // if an exception occurred, show an error message
            Log.e(this.getClass().toString(), e.getMessage());

If you have questions about how to invoke DropboxTask in your MainActivity class, refer to our getting started tutorial, but find the correct TextView with TextView textView = (TextView) findViewById(R.id.result);.

What next?

We're all finished! This Android application can create a text file out of any string you might produce while coding. Check out the rest of the 2000+ Choreos in our Library and discover all sorts of valuable data that you could save to Dropbox.

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.