Last updated: Jun-04-2024
Overview
Cloudinary's Kotlin SDK provides simple, yet comprehensive image and video transformation, optimization, and delivery capabilities that you can implement using code that integrates seamlessly with your existing Kotlin or Java application.
Key features
- Uses Cloudinary's new SDK action based syntax with enhanced code autocomplete.
- Actions and transformations are immutable, for easier and safer code reuse.
- Makes use of Type-Safe Builders to create a Cloudinary DSL layer. The transformation syntax is therefore simpler and more human-readable when compared with the existing Java or Android SDKs.
Get started
Install and configure the SDK in your project to get started.
Add Kotlin SDK dependency
Add the SDK to your project as a dependency, we recommend using a build management tool such as Maven or Gradle to do this.
Using Gradle
Add the Cloudinary Kotlin SDK to the dependencies section of your build.gradle
file.
Using Maven
Add the Cloudinary Kotlin SDK to the list of dependencies in your pom.xml
file.
Add your Cloudinary configuration
The Cloudinary
class is the main entry point for using the library. Your cloud_name
is required to create an instance of this class. Your api_key
and api_secret
are used to perform secure API calls to Cloudinary (e.g., image and video uploads). Setting the configuration parameters can be done either programmatically using an appropriate constructor of the Cloudinary class or globally using an environment variable. You can find your configuration credentials on the API Keys page of the Cloudinary Console Settings.
In addition to the required configuration parameters, you can define a number of optional configuration parameters if relevant.
Here's an example of setting configuration parameters in your Kotlin application:
Example
Here is a simple example for generating a Cloudinary image URL, including a resize transformation, using the Kotlin SDK:
- See all possible transformations in the Transformation URL API reference.
- See more examples of image and video transformations using the Cloudinary Kotlin library.
Thanks for your time!
Migration from Java/Android
To use the Kotlin SDK with your existing Java and Android projects, we recommend adding your own Kotlin classes as a bridge between our SDK and your Java code. You can therefore take advantage of the simpler transformation building syntax.
For example, here's a simple Kotlin transformation:
And the corresponding code in Java:
You can add a new Kotlin file to act as a bridge e.g.:
You can then call this specific function from your Java code:
- See examples of powerful image and video transformations using Kotlin code
and see our image transformations and video transformations docs. - Stay tuned for updates with the Programmable Media Release Notes and the Cloudinary Blog.
- Take a look at our Android SDK as an alternative for Android development with Cloudinary.