cloudinary / cloudinary_kotlin

Cloudinary Kotlin SDK library
MIT License
11 stars 4 forks source link
cloudinary-sdk hacktoberfest

Cloudinary Kotlin SDK

Build Status

About

The Cloudinary Kotlin SDK allows you to quickly and easily integrate your application with Cloudinary. Effortlessly optimize and transform your cloud's assets.

Additional documentation

This Readme provides basic installation and usage information. For the complete documentation, see the Kotlin SDK Guide.

Table of Contents

Key Features

Version Support

SDK Version Kotlin Version
1.x > 1.0

Installation

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>

Usage

Setup

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>")

Transform and Optimize Assets

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

Uploading Assets

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
    }
}

Contributions

See contributing guidelines.

Get Help

If you run into an issue or have a question, you can either:

About Cloudinary

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.

Additional Resources

Licence

Released under the MIT license.