Programmable Media

Kotlin SDK

Last updated: Dec-18-2023

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.

Tip
In this guide you'll learn how to get started with the Kotlin SDK, but if you are not familiar with Cloudinary, we advise reading How to integrate Cloudinary first for a high-level overview of integrating Cloudinary into your code, and an introduction to the main concepts.

Related topics
This guide relates to the latest released version of the Cloudinary Kotlin library.

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 in the Programmable Media Dashboard of the Cloudinary Console.

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:

simple example

Learn more about transformations

Help us improve our SDK
We'd love to hear your thoughts on using our Kotlin SDK. Please take a moment to complete this short survey.
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:

Related topics

✔️ Feedback sent!

Rate this page: