Dropbox is a file hosting service that allows users to create a special folder that syncs files across devices. Mule can integrate with Dropbox using the Dropbox connector and OAuth2 authentication. Example flows show how to retrieve account info, download/upload/delete files, and create folders on Dropbox from Mule applications. The Dropbox connector provides an easy way to connect to Dropbox cloud storage and perform common operations.
2. What is Dropbox?
Dropbox was founded in 2007
Dropbox is a file hosting service operated by Dropbox, Inc. ,
headquartered in San Francisco, California
It offers cloud storage, file synchronization, personal cloud,
and client software for Microsoft Windows, Mac OS
X, Linux, Android, iOS, BlackBerry OS, Windows
Phone and web browsers
Dropbox allows users to create a special folder on their
computers, which Dropbox then synchronizes so that it
appears to be the same folder (with the same contents)
regardless of which computer is used to view it. Files placed
in this folder are also accessible via the Dropbox website and
mobile apps
3. Versions and Assumptions
In this presentation, we are using
Dropbox Cloud Connector 3.3.0
Anypoint Studio
Mule ESB Server 3.5.2
Mule requester Module 1.2.0
To integrate Dropbox with Mule ESB, you will need a
Dropbox account
You will need to create a new Dropbox app under Dropbox
developer apps to be able to communicate with your
Dropbox account from Mule ESB application
We will be using OAuth2 authentication to connect to
Dropbox using Mule ESB Dropbox Cloud Connector
4. Configuring Dropbox
Go to https://www.dropbox.com/developers/apps
Click on Create app button
Click on Dropbox API app
5. Select “Files and datastores” radio button
Select “No - My app needs access to files already on Dropbox” radio button
Select “All file types - My app needs access to a user's full Dropbox” radio
button
Provide an app name and click on Create app button
Provide a redirect URI for OAuth2 and click on Add button
Make a note of the App key, App secret URI as these will be used in our Mule
application
A sample screen shot is shown in the next slide
6.
7. Configuring Global properties in
Mule
Create a new Mule Application
Click on Global Elements tab in
your main flow
Click on Create Button
Select Property Placeholder
component
Provide your property file location
and click on OK
8. Configuring Dropbox
Connector
Click on Global Elements tab in your main flow
Click on Create Button
Select Dropbox under Connector Configuration group
Add your Dropbox App Key value to App Key text box
Add your Dropbox Secret value to App Secret text box
Click on Oauth tab and specify domain, local port, remote port and path
values. These values should be same as provided in Redirect URL during
Dropbox configuration
A screen shot and sample XML configuration is shown in the next slide
9.
10. Mule Flow for Dropbox
Authentication
Configure a flow as shown in the below picture
The XML configuration for this flow is given in the next slide
11. If the app authorizes to Dropbox app successfully, the connector returns two flow
variables to Mule ESB flow which are “_oauthVerifier” and “OAuthAccessTokenId”
Using Choice router, we are checking weather the flow received a valid
“OAuthAccessTokenId” or not and based on the response we are determining the
success or failure of the Dropbox authorization
12. Deploy your Mule application
Hit the following URL on the browser
http://localhost:2222/dropboxcloudconnect
Dropbox will ask you to authorize your new app to connect to Dropbox as shown
below. Below screen will be prompted every time you run the app
Click on Allow button and you should see a message printed on your browser as
“Authorization is successful”
13. Mule Flow for retrieving Dropbox Account Info
Let’s extend the previous authorize flow and use the authentication
token to retrieve the logged in user account information from Dropbox.
Change your Mule flow as per the following flow picture
14. The XML configuration for the flow is as follows
15. In this flow, we have used get-account operation provided by Dropbox connector
to retrieve the logged in user details and print them on the browser using Object
to JSON message transformer
Deploy your app
Hit the following URL on the browser
http://localhost:2222/dropboxcloudconnect
You should now see the logged in user details printed on your browser in JSON
format
16. Mule Flow for downloading a File
Modify your previous flow as per the following picture
The XML configuration for this flow is given in the next slide
17.
18. Deploy your Mule application
Hit the following URL on the browser
http://localhost:2222/dropboxcloudconnect
A message should be printed on your browser as “File downloaded successfully”
You should now see a file downloaded on your system at the given folder
location
19. Mule Flow for uploading a file
Modify your previous flow as per the following picture
Observe that we are using Mule Requestor module to read a file in the
middle of the flow. This component is not available by default and hence
you need to install this from Help -> Install New Software
The XML configuration for this flow is given in the next slide
20.
21. Deploy your Mule application
Hit the following URL on the browser
http://localhost:2222/dropboxcloudconnect
A message should be printed on your browser as “File uploaded successfully”
A new file should now be uploaded on your Dropbox at the specified path
22. Mule Flow for deleting a file
Modify your previous flow as per the following picture
The XML configuration for this flow is given in the next slide
23.
24. Deploy your Mule application
Hit the following URL on the browser
http://localhost:2222/dropboxcloudconnect
A message should be printed on your browser as “File deleted successfully”. In my
code I am using a file name which already exists on my Dropbox. If the files does
not exist, application will throw an error
Once the flow execution completes, the specified file will be deleted from
Dropbox
25. Mule flow for creating a folder
Modify your previous flow as per the following picture
The XML configuration for this flow is given in the next slide
26.
27. Deploy your Mule application
Hit the following URL on the browser
http://localhost:2222/dropboxcloudconnect
A message should be printed on your browser as “Folder Created successfully”
A new folder should now be created on your Dropbox at the specified path
28. Conclusion
Mule ESB Dropbox connector provides an easy way to
connect to Dropbox cloud using OAuth2 authentication and
allows performing several operations
The latest Dropbox connector is simpler to use compared to
the previous version of Dropbox connectors
Dropbox Connector is available for Mule ESB community
edition
Mule Request module allows to retrieve a file in the middle
of the flow and is very easy to use
You can use Dropbox connector like FTP connector in your
application to upload files directly on Dropbox cloud storage