Ce contenu n'est pas disponible dans la langue sélectionnée.
Chapter 90. Dropbox Component
Available as of Camel version 2.14
The dropbox: component allows you to treat Dropbox remote folders as a producer or consumer of messages. Using the Dropbox Java Core API (reference version for this component is 1.7.x), this camel component has the following features:
- As a consumer, download files and search files by queries
- As a producer, download files, move files between remote directories, delete files/dir, upload files and search files by queries
Maven users will need to add the following dependency to their pom.xml
for this component:
<dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-dropbox</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency>
90.1. URI format
dropbox://[operation]?[options]
Where operation is the specific action (typically is a CRUD action) to perform on Dropbox remote folder.
90.2. Operations
Operation | Description |
---|---|
| deletes files or directories on Dropbox |
| download files from Dropbox |
| move files from folders on Dropbox |
| upload files on Dropbox |
| search files on Dropbox based on string queries |
Operations require additional options to work, some are mandatory for the specific operation.
90.3. Options
In order to work with Dropbox API you need to obtain an accessToken and a clientIdentifier.
You can refer to the Dropbox documentation that explains how to get them.
The Dropbox component has no options.
The Dropbox endpoint is configured using URI syntax:
dropbox:operation
with the following path and query parameters:
90.3.1. Path Parameters (1 parameters):
Name | Description | Default | Type |
---|---|---|---|
operation | Required The specific action (typically is a CRUD action) to perform on Dropbox remote folder. | DropboxOperation |
90.3.2. Query Parameters (12 parameters):
Name | Description | Default | Type |
---|---|---|---|
accessToken (common) | Required The access token to make API requests for a specific Dropbox user | String | |
client (common) | To use an existing DbxClient instance as DropBox client. | DbxClientV2 | |
clientIdentifier (common) | Name of the app registered to make API requests | String | |
localPath (common) | Optional folder or file to upload on Dropbox from the local filesystem. If this option has not been configured then the message body is used as the content to upload. | String | |
newRemotePath (common) | Destination file or folder | String | |
query (common) | A space-separated list of sub-strings to search for. A file matches only if it contains all the sub-strings. If this option is not set, all files will be matched. | String | |
remotePath (common) | Original file or folder to move | String | |
uploadMode (common) | Which mode to upload. in case of add the new file will be renamed if a file with the same name already exists on dropbox. in case of force if a file with the same name already exists on dropbox, this will be overwritten. | DropboxUploadMode | |
bridgeErrorHandler (consumer) | Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. | false | boolean |
exceptionHandler (consumer) | To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. | ExceptionHandler | |
exchangePattern (consumer) | Sets the exchange pattern when the consumer creates an exchange. | ExchangePattern | |
synchronous (advanced) | Sets whether synchronous processing should be strictly used, or Camel is allowed to use asynchronous processing (if supported). | false | boolean |
90.4. Spring Boot Auto-Configuration
The component supports 2 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
camel.component.dropbox.enabled | Enable dropbox component | true | Boolean |
camel.component.dropbox.resolve-property-placeholders | Whether the component should resolve property placeholders on itself when starting. Only properties which are of String type can use property placeholders. | true | Boolean |
90.5. Del operation
Delete files on Dropbox.
Works only as Camel producer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| Folder or file to delete on Dropbox |
90.5.1. Samples
from("direct:start") .to("dropbox://del?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1") .to("mock:result"); from("direct:start") .to("dropbox://del?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1/file1.tar.gz") .to("mock:result");
90.5.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| name of the path deleted on dropbox |
90.5.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| name of the path deleted on dropbox |
90.6. Get (download) operation
Download files from Dropbox.
Works as Camel producer or Camel consumer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| Folder or file to download from Dropbox |
90.6.1. Samples
from("direct:start") .to("dropbox://get?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1/file1.tar.gz") .to("file:///home/kermit/?fileName=file1.tar.gz"); from("direct:start") .to("dropbox://get?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1") .to("mock:result"); from("dropbox://get?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1") .to("file:///home/kermit/");
90.6.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| in case of single file download, path of the remote file downloaded |
| in case of multiple files download, path of the remote files downloaded |
90.6.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| in case of single file download, stream representing the file downloaded |
| in case of multiple files download, a map with as key the path of the remote file downloaded and as value the stream representing the file downloaded |
90.7. Move operation
Move files on Dropbox between one folder to another.
Works only as Camel producer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| Original file or folder to move |
|
| Destination file or folder |
90.7.1. Samples
from("direct:start") .to("dropbox://move?accessToken=XXX&clientIdentifier=XXX&remotePath=/root/folder1&newRemotePath=/root/folder2") .to("mock:result");
90.7.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| name of the path moved on dropbox |
90.7.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| name of the path moved on dropbox |
90.8. Put (upload) operation
Upload files on Dropbox.
Works as Camel producer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| add or force this option specifies how a file should be saved on dropbox: in case of "add" the new file will be renamed if a file with the same name already exists on dropbox. In case of "force" if a file with the same name already exists on dropbox, this will be overwritten. |
|
| Folder or file to upload on Dropbox from the local filesystem. If this option has been configured then it takes precedence over uploading as a single file with content from the Camel message body (message body is converted into a byte array). |
|
| Folder destination on Dropbox. If the property is not set, the component will upload the file on a remote path equal to the local path. With Windows or without an absolute localPath you may run into an exception like the following:
Caused by: java.lang.IllegalArgumentException: 'path': bad path: must start with "/": "C:/My/File" |
90.8.1. Samples
from("direct:start").to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&uploadMode=add&localPath=/root/folder1") .to("mock:result"); from("direct:start").to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&uploadMode=add&localPath=/root/folder1&remotePath=/root/folder2") .to("mock:result");
And to upload a single file with content from the message body
from("direct:start") .setHeader(DropboxConstants.HEADER_PUT_FILE_NAME, constant("myfile.txt")) .to("dropbox://put?accessToken=XXX&clientIdentifier=XXX&uploadMode=add&remotePath=/root/folder2") .to("mock:result");
The name of the file can be provided in the header DropboxConstants.HEADER_PUT_FILE_NAME
or Exchange.FILE_NAME
in that order of precedence. If no header has been provided then the message id (uuid) is used as the file name.
90.8.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| in case of single file upload, path of the remote path uploaded |
| in case of multiple files upload, string with the remote paths uploaded |
90.8.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| in case of single file upload, result of the upload operation, OK or KO |
| in case of multiple files upload, a map with as key the path of the remote file uploaded and as value the result of the upload operation, OK or KO |
90.9. Search operation
Search inside a remote Dropbox folder including its sub directories.
Works as Camel producer and as Camel consumer.
Below are listed the options for this operation:
Property | Mandatory | Description |
---|---|---|
|
| Folder on Dropbox where to search in. |
|
|
A space-separated list of sub-strings to search for. A file matches only if it contains all the sub-strings. If this option is not set, all files will be matched. The query is required to be provided in either the endpoint configuration or as a header |
90.9.1. Samples
from("dropbox://search?accessToken=XXX&clientIdentifier=XXX&remotePath=/XXX&query=XXX") .to("mock:result"); from("direct:start") .setHeader("CamelDropboxQuery", constant("XXX")) .to("dropbox://search?accessToken=XXX&clientIdentifier=XXX&remotePath=/XXX") .to("mock:result");
90.9.2. Result Message Headers
The following headers are set on message result:
Property | Value |
---|---|
| list of file path founded |
90.9.3. Result Message Body
The following objects are set on message body result:
Object type | Description |
---|---|
| list of file path founded. For more information on this object refer to Dropbox documentation, |