Java SDK


Cloudinary is a cloud-based service that provides an end-to-end image and video management solution. The Java SDK provides simple, yet comprehensive file upload, administration, manipulation, optimization, and delivery capabilities that you can implement using code that integrates seamlessly with your existing Java application.

Quick example: Image transformation

The following Java code generates an https delivery URL for image below including all of the following transformations:

  • Thumbnail crop to a size of 150x150 pixels using face detection gravity to automatically determine the location for the crop
  • Rounded corners with a 20 pixel radius
  • Sepia effect
  • Overlay of the Cloudinary logo on the southeast corner (with a slight offset). The logo is scaled down to a 50 pixel width, with increased brightness, and partial transparency (opacity = 60%)
  • Rotated by 10 degrees
  • Converted to and delivered in PNG format (the originally uploaded image was a JPG)
cloudinary.url().transformation(new Transformation()

// This code outputs the following URL:
150x150 PNG

Quick example: File upload

The following Java code uploads the dog.mp4 video to the specified account sub-folder using the public_id, my_dog. The video will overwrite the existing my_dog video if it exists. When the video upload is complete, the specified notification URL will receive details about the uploaded media asset.

Map params = ObjectUtils.asMap(
   "public_id", "my_folder/my_sub_folder/my_dog", 
   "overwrite", true,
   "notification_url", "http://mysite/notify_endpoint",
   "resource_type", "video"         
Map uploadResult = cloudinary.uploader().upload(new File("doc.mp4"), params);

Java Library Features

Cloudinary provides an open source Java library for further simplifying the integration:

  • Build URLs for transformation & manipulation
  • API wrappers: file upload, administration, sprite generation and more
  • JSP tag library to ease and facilitate the inclusion, transformation, upload, and storage in a Java EE web application
  • Server-side file upload + direct unsigned file upload from the browser using the jQuery plugin

The library is built for Java 6 / JSP 2.0 and will work with higher versions. The following are resources which serve as a good starting point to better familiarize yourself with the library:

Choosing the right Maven package

The Maven repository includes several packages ("artifacts") to choose from:

  • cloudinary-http - for general Java applications. It utilizes the Apache HTTP libraries.
    • cloudinary-http44 - Cloudinary Apache HTTP 4.4 Library
    • cloudinary-http43 - Cloudinary Apache HTTP 4.3 Library
    • cloudinary-http42 - Cloudinary Apache HTTP 4.2 Library
  • cloudinary-taglib - provides a Java Tag Library for J2EE applications
  • cloudinary-android - provides support for android applications

Java capitalization and data type guidelines

When using the Java SDK, keep these guidelines in mind:

  • Parameter names: snake_case. For example: public_id
  • Classes: PascalCase. For example: CloudinaryImageTag
  • Methods: camelCase. For example: imageUploadTag
  • Pass parameter data as: Map

Java - Getting started guide


The easiest way to start using Cloudinary's Java library is to use Maven.

  • Download and install Maven. Follow for reference.
  • Create a maven project. See example here.
  • Add the Cloudinary dependency to the list of dependencies in the pom.xml :

        <version>[Cloudinary API version, e.g. 1.1.3]</version>
  • If you are building a Java EE web application you should consider using the tag library by adding:

        <version>[Cloudinary API version, e.g. 1.1.3]</version>

When using in Java code import the appropriate package:

import com.cloudinary.*;

When using in a JSP view import the tag library:

<%@taglib uri="" prefix="cl" %>


Your Cloud Name account parameter is required to create instance of Cloudinary class that is main entry point for using the library. API Key and API Secret are further needed to perform secure API calls to Cloudinary (e.g., image and video uploads). See Account and API setup for more details.

Setting the configuration parameters can be done either programmatically using appropriate constructor of Cloudinary class or globally using an environment variable.

You can find your configuration parameters in the dashboard of our Management Console.

Here's an example of setting configuration parameters in your Java application:

import com.cloudinary.*;
Cloudinary cloudinary = new Cloudinary(ObjectUtils.asMap(
  "cloud_name", "my_cloud_name",
  "api_key", "my_api_key",
  "api_secret", "my_api_secret"));

In a Java EE environment you can set an environment variable available to your Java EE container:


This will enable you to receive a Cloudinary instance:

Cloudinary cloudinary = Singleton.getCloudinary();

Or you can directly register a Cloudinary instance in your initializer code:

SingletonManager manager = new SingletonManager();

Note: The tags in the tag library require an instance to be available in the Singleton to function correctly.

See Configuration options for more details and additional configuration methods.

3Upload media assets

You can upload images, videos or any other files from your server. Uploading is done over HTTPS using a secure protocol based on the api_key and api_secret parameters you provide.

The following command uploads a local file to Cloudinary:

import java.util.Map;
File toUpload = new File("daisy.png");
Map uploadResult = cloudinary.uploader().upload(toUpload, ObjectUtils.emptyMap());

Alternatively, you can a specify a local path, a public HTTP URL, an S3 URL or an actual media file's data. For example:

Map uploadResult = cloudinary.uploader().upload("", ObjectUtils.emptyMap());

Each media asset uploaded to Cloudinary is assigned an unique Public ID and is available for immediate delivery and transformation. The upload method returns a Map of the uploaded image's properties including image URL and Public ID. In case of an HTTP error or an application server error a RuntimeException is thrown. The returned Map is a representation of the underlying JSON object returned from the with content similar to that shown in the following example:


As you can see in the following example, with a single call you can define your own Public ID, apply an incoming transformation before storing the resource in the cloud, generate derived resources eagerly and assign tags to uploaded resources:

import java.util.Arrays;
Map result = cloudinary.uploader().upload(new File("daisy.png"), ObjectUtils.asMap(
  "public_id", "sample_id",
  "transformation", new Transformation().crop("limit").width(40).height(40),
  "eager", Arrays.asList(
    new Transformation().width(200).height(200)
    new Transformation().width(100).height(150)
  "tags", "special, for_homepage"));

Many more upload options as well as direct uploading from the browser are detailed here: Java image upload and Java video upload.

4Display and manipulate images

You can access uploaded resources using the URL contained in the upload result immediately after uploading or build a URL using various helper methods of the Url class which could be accessed via an instance of Cloudinary.

String url = cloudinary.url().format("jpg")
  .transformation(new Transformation().width(250).height(168).crop("fit"))

Or in a Java EE JSP view:

<link rel="shortcut icon"
      href="<cl:url src="sample" width="16" height="16" crop="fit" format="jpg"/>"/>

For example, you can use that url and feed it to an HTML image tag or you can use a Cloudinary helper function:

String imageHtml = cloudinary.url().format("jpg")
  .transformation(new Transformation().width(100).height(150).crop("fill"))
  .imageTag("sample", Cludinary.asMap("alt","Sample Image"));
100x150 JPG

Or in a JSP view:

<cl:image src="sample" format="jpg" width="100" height="150" crop="fill" effect="sepia"/>
100x150 JPG

This is equivalent to:

<img src=',e_sepia,h_150,w_100/sample.jpg' 
     width='100' height='150' />

Using simple parameters you can perform powerful manipulations. The Java library builds Cloudinary URLs that you can embed in your web and mobile views for dynamically transforming your uploaded resources in the cloud and delivering the results through a fast CDN with advanced caching.

You can easily convert formats, resize, perform face detection based cropping, apply effects and filters, append textual layers or watermarks and more.

The following command, for example, embeds a JPG thumbnail of a profile photo fetched from Facebook in real-time, crops it to a circle, applies a sepia effect and delivers it optimized through a CDN:

  new Transformation()

//JSP view
<cl:image src="billclinton" type="facebook" format="jpg" width="90" height="98" 
  crop="fill" gravity="face" radius="max" effect="sepia"/>
90x98 JPG

For a full list of supported transformations and their usage, refer to Image transformations. For more details about Cloudinary's transformation and manipulation in Java, see Java image manipulation and Java video manipulation.

5Sample projects

To find additional useful code samples and learn how to integrate Cloudinary with your Java applications, take a look at our Sample Projects. These projects are based on the Spring MVC v3.2.

Photo Album: A fully working web application that allows you to uploads photos, maintain a database with references to them, list them with their metadata, and display them using various cloud-based transformations. Image uploading is performed both from the server side and directly from the browser using a jQuery plugin.

6What's next

Sign up for a free account if you haven't done so already. Follow the steps above and try Cloudinary out. Finished all steps? That's just an example of what Cloudinary can offer. Here's some additional reading material to help you get the best out of Cloudinary: