Dropbox cloud storage service that allows users to store, share, and manage files online.
The ballerinax/dropbox
package offers APIs to connect and interact with Dropbox API endpoints, specifically based on Dropbox API v2.
To use the Dropbox connector, you must have access to the Dropbox API. Dropbox uses OAuth 2.0, an open specification, to authorize access to data. To get an OAuth token from Dropbox to enable Dropbox Connector to access your Dropbox account via the API you’ll need to create a new app on the DBX Platform.
- Navigate to https://www.dropbox.com/developers/apps and sign up to create an account (or log in if you already have an account)
- Select “Create app”.
- Choose an API, type of access you need, and give your app a name.
For reference, please use the Dropbox OAuth guide.
Once you select “Create app”, a page will load that displays information about your newly created app. To generate an access token scroll down to “OAuth 2” and click “Generate” beneath “Generated access token.” The token will display as a long string of characters. Copy this token for use with the Dropbox connector.
To use the Dropbox
connector in your Ballerina application, update the .bal
file as follows:
Import the dropbox
module.
import ballerinax/dropbox;
- Create a
Config.toml
file and, configure the obtained credentials in the above steps as follows:
token = "<Enter your token here>"
- Create a dropbox:ConnectionConfig with the obtained access token and initialize the connector with it.
configurable string token = ?;
dropbox:ConnectionConfig config = {auth: {token}};
final dropbox:Client dropbox = check new(config, serviceUrl = "https://api.dropboxapi.com/2");
Now, utilize the available connector operations.
Create a Folder
public function main() returns error? {
dropbox:FolderMetadataResponse createFolder = check dropbox->/files/create_folder_v2.post(
payload = {
path: "/path/to/folder",
autorename: true
}
);
}
bal run
The Dropbox
connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:
-
Download and install Java SE Development Kit (JDK) version 17. You can download it from either of the following sources:
Note: After installation, remember to set the
JAVA_HOME
environment variable to the directory where JDK was installed. -
Download and install Ballerina Swan Lake.
-
Download and install Docker.
Note: Ensure that the Docker daemon is running before executing any tests.
-
Export Github Personal access token with read package permissions as follows,
export packageUser=<Username> export packagePAT=<Personal access token>
Execute the commands below to build from the source.
-
To build the package:
./gradlew clean build
-
To run the tests:
./gradlew clean test
-
To build the without the tests:
./gradlew clean build -x test
-
To run tests against different environments:
./gradlew clean test -Pgroups=<Comma separated groups/test cases>
-
To debug the package with a remote debugger:
./gradlew clean build -Pdebug=<port>
-
To debug with the Ballerina language:
./gradlew clean build -PbalJavaDebug=<port>
-
Publish the generated artifacts to the local Ballerina Central repository:
./gradlew clean build -PpublishToLocalCentral=true
-
Publish the generated artifacts to the Ballerina Central repository:
./gradlew clean build -PpublishToCentral=true
As an open-source project, Ballerina welcomes contributions from the community.
For more information, go to the contribution guidelines.
All the contributors are encouraged to read the Ballerina Code of Conduct.
- For more information go to the
dropbox
package. - For example demonstrations of the usage, go to Ballerina By Examples.
- Chat live with us via our Discord server.
- Post all technical questions on Stack Overflow with the #ballerina tag.