Upload a text file to Dropbox on iOS


Here we'll show you how to use our iOS SDK to upload a file to Dropbox. For this tutorial, you will need the iOS 7 SDK and Xcode 6.

Set Up Your Code Project

For simplicity's sake, we'll create a command line tool that will print its results to the Xcode console. For an example of using Temboo with a UI-based application (as you would on an iPhone or iPad) check out our Facebook OAuth example.

1Create a new Xcode project: OS X > Application > Command Line Tool.

2Name it TembooTest, select Objective-C as the Language, and click Next to save your new project (the other fields are optional and may be left blank).

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

4Download and extract the Temboo iOS SDK, noting where it's been saved.

5Click on the folder that contains your project's code (it should be called TembooTest and contain a file called main.m), then select Add Files to TembooTest from the File menu. Browse to where you saved the Temboo SDK, locate and click on the core folder inside the SDK src folder. Make sure that Copy items if needed is unchecked and Create groups is selected, and then click Add.

6Repeat the above steps to add the TMBDropbox.h and TMBDropbox.m files located in the SDk's src/library folder.

7You'll need a free Dropbox account. If you don't already have one, you can sign up here.

8If you haven't already, create a Dropbox app in the Dropbox App Console.

When asked to choose an API, select Dropbox API. Choose the type of access your application will need: App folder or Full Dropbox. The app name can be whatever you like. When you're done, click Create app.

Dropbox App Console

To Access to Your Own Dropbox

9If you will only be needing access to your own account, you can generate an Access Token in the Dropbox App Console. Click the Generate button in the OAuth 2 section of your app settings page.

Generating a Dropbox access token for your own account

To Access to Another User's Dropbox

10In order to access Dropbox accounts other than your own, you will need to complete the OAuth process. If you only need access to your own account, you can skip ahead to the next section.

To begin, go to Dropbox > OAuth > InitializeOAuth in the Temboo code generation library. In the INPUT section of the page, enter the AppKey found on your app settings page within the Dropbox App Console.

Supplying inputs needed for Dropbox Initialize OAuth

11Click the Generate Code button to run InitializeOAuth from the Temboo site. Scroll down to the OUTPUT section of the page. Save the CallbackID to use in the next steps.

Outputs returned by Initialize OAuth

12The owner of the Dropbox account that your application needs to access will need to visit the AuthorizationURL found in the OUTPUT section. They should click the Allow button on the page to grant the application permission to access their account. Once they see a blank page in the browser, it's safe to close the page.

Allowing your app to access a Dropbox account

13Once permission has been granted on the AuthorizationURL page, you're ready to complete the OAuth process. Visit Dropbox > OAuth > FinalizeOAuth in the Temboo code generation library. In the INPUT section of the page, enter the AppKey and AppSecret found on your app settings page in the Dropbox App Console.

Supply the CallbackID that was returned in the OUTPUT section of the InitializeOAuth page.

Required inputs for Finalize OAuth

14Now, with all the required inputs in place, click the Generate Code button to run FinalizeOAuth from the Temboo site. Scroll down once again to the OUTPUT section of the page. Here you'll find the AccessToken you'll need for any Dropbox processes for this user's account. Save it for later.

Output returned by Finalize OAuth

Generate the Code

15 Go to the Dropbox > Files > Upload page in our code generation library. From the drop down menu at the top of the page, select iOS.

selecting iOS as your development platform

16In the INPUT section of the page, enter your Dropbox AccessToken. Click on Save Profile in the upper right corner of the INPUT section to save your Dropbox credentials for easy use in other Dropbox Choreos in the future. Using a Temboo Profile will also make your code simpler and more secure.

Saving credentials to a Temboo Profile

17Enter the file location and filename for your new file in the Path field. To create a text file in the root directory of your Dropbox account, try entering /test.txt for your Path.

18Now supply the FileContent of your text file. We'll just use "Hello world!".

At this point, your INPUT section should look something like this:

Required inputs to upload a file

19We need to tell Dropbox that our file content is plain text rather than Base64 encoded binary data. To do so, click on OPTIONAL INPUT at the bottom of the INPUT section to reveal more input fields. In the ContentType field, enter text/plain. You can leave the other fields blank.

Specifying the Content Type

20Click the Generate Code button at the bottom of the INPUT section to test the file upload from the Temboo site. You'll see some details about your uploaded file in the OUTPUT section. If you go to your folder in Dropbox, you'll see your file appear.

File metadata returned by the upload file process

Try It Out

21Dropbox won't allow you to upload a file if there's already a file with the location and filename specified in the Path input. Delete your test file in Dropbox so that you can run the same code again from your iOS application.

22Copy the generated iOS code from your browser and paste it into your project's main.m file between the Foundation.h import statement and the main method.

23Finally, update your main method to run the Choreo, and then run your code.

24Go check your Dropbox and you’ll find a new text file from your iOS application waiting for you!

What next?

We're all finished! This iOS 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.


Back