The Cloudinary Kotlin SDK allows you to quickly and easily integrate your application with Cloudinary. Effortlessly optimize and transform your cloud's assets.
This Readme provides basic installation and usage information. For the complete documentation, see the Kotlin SDK Guide.
SDK Version | Kotlin Version |
---|---|
1.x | > 1.0 |
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.
implementation 'com.cloudinary:kotlin-url-gen:1.10.0'
Using Maven:
Add the Cloudinary Kotlin SDK to the list of dependencies in your pom.xml
file.
<dependency>
<groupId>com.cloudinary</groupId>
<artifactId>kotlin-url-gen</artifactId>
<version>1.10.0</version>
<type>pom</type>
</dependency>
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 also needed 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 account-specific configuration parameters in the Dashboard page of your account console.
Here's an example of setting configuration parameters in your Kotlin application:
import com.cloudinary.*
...
private val cloudinary = Cloudinary("cloudinary://<your-api-key>:<your-api-secret>@<your-cloud-name>")
Generate a Cloudinary URL using the cloudinary.media
helper method and pass this to your image or video view:
For example, to generate a url for an image called sample
on the demo
account, and resize it using the fill method:
A transformation is also added to the image - cropping and using the sepia effect:
val cloudinary = Cloudinary("cloudinary://@demo")
val url = cloudinary.image {
publicId("sample")
resize(Resize.fill {
width(100)
height(150)
})
}
println(url.generate())
This will output the following url:
https://res.cloudinary.com/demo/image/upload/c_fill,h_150,w_100/sample.jpg
To upload a file you need to call you cloudinary
object with uploader()
, here's an example:
cloudinary.uploader().upload(imageFile) {
params {
uploadPreset = "sample_preset"
}
options {
unsigned = true
}
}
If you run into an issue or have a question, you can either:
Cloudinary is a powerful media API for websites and mobile apps alike, Cloudinary enables developers to efficiently manage, transform, optimize, and deliver images and videos through multiple CDNs. Ultimately, viewers enjoy responsive and personalized visual-media experiences—irrespective of the viewing device.
Released under the MIT license.