> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Java SDK


[sample-projects-link]:https://github.com/cloudinary/cloudinary_java/tree/master/samples
[changelog-link]: https://github.com/cloudinary/cloudinary_java/blob/master/CHANGELOG.md

The Cloudinary Java SDK provides simple, yet comprehensive image and video upload, transformation, optimization, and delivery capabilities through the [Cloudinary APIs](cloudinary_references#url_and_rest_apis), that you can implement using code that integrates seamlessly with your existing Java application.
> **INFO**: :title=SDK security upgrade, June 2025

We recently released an enhanced security version of this SDK that improves the validation and handling of input parameters. We recommend upgrading to the [latest version][changelog-link] of the SDK to benefit from these security improvements.

## How would you like to learn?

{table:class=no-borders overview}Resource | Description 
--|--
[Java quick start](java_quickstart) | Get up and running in five minutes with a walk through of installation, configuration, upload, management and transformations.
[Sample projects][sample-projects-link] | Explore sample projects to see how to implement Cloudinary functionality such as upload and delivery with transformations.
[Cloudinary Java SDK GitHub repo](https://github.com/cloudinary/cloudinary_java) | Explore the source code and see the [CHANGELOG][changelog-link] for details on all new features and fixes from previous versions. 
[Video tutorials](tutorial_screencasts) | Watch tutorials relevant to your use cases to learn how to use Cloudinary features. 
 | Try the free [Introduction to Cloudinary for Java Developers](https://training.cloudinary.com/courses/introduction-to-cloudinary-for-java-developers-90-minute-course) online course, where you can learn how to upload, manage, transform and optimize your digital assets.

Other helpful resources...

This guide focuses on how to set up and implement popular Cloudinary capabilities using the Java SDK, but it doesn't cover every feature or option. Check out these other resources to learn about additional concepts and functionality in general. 

{table:class=no-borders overview}Resource | Description 
--|--
[Developer kickstart](dev_kickstart) |A hands-on, step-by-step introduction to Cloudinary features.
[Glossary](cloudinary_glossary) | A helpful resource to understand Cloudinary-specific terminology.
[Guides](programmable_media_guides) | In depth guides to help you understand the many, varied capabilities provided by the product. 
[References](cloudinary_references) | Comprehensive references for all APIs, including Java code examples.

## Install

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

> **NOTE**: We recommend updating the version number shown below to use the [latest version](https://github.com/cloudinary/cloudinary_java) of the Java SDK.

### Prerequisites

If you don't already have Maven installed:

1. Download and install Maven (the build tool). Refer to [https://maven.apache.org/download.cgi](https://maven.apache.org/download.cgi) for package downloads and detailed installation instructions.
1. Create a Maven project. See example [here](https://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project).

### Choose the right Cloudinary package

The Maven repository includes several [Cloudinary Java packages](https://central.sonatype.com/search?q=g:com.cloudinary&smo=true) ("artifacts"). Choose the package(s) that fit your application type:

* **cloudinary-http5** - for general Java applications. It utilizes the Apache HTTP libraries. When working with SDK versions v2.x, only HTTP 5 is available.
* **cloudinary-taglib** - provides a Java Tag Library for J2EE applications
* **cloudinary-android** - provides support for Android applications

### Add Cloudinary to your project

1. Add the appropriate Cloudinary dependency to the list of dependencies in your **pom.xml**.

    For general Java applications, add **cloudinary-http5**:

    ```xml
    <dependencies>
        ...
        <dependency>
            <groupId>com.cloudinary</groupId>
            <artifactId>cloudinary-http5</artifactId>
            <version>[Cloudinary Java SDK version, e.g. 2.0.0]</version>
        </dependency>
    </dependencies>
    ```

1. If you're building a Java EE web application, also add the **cloudinary-taglib** package:

    ```xml          
    <dependencies>
        ...
        <dependency>
            <groupId>com.cloudinary</groupId>
            <artifactId>cloudinary-taglib</artifactId>
            <version>[Cloudinary Java SDK version, e.g. 2.0.0]</version>
        </dependency>
    </dependencies>
    ```

## Configure

### Set required configuration parameters

To use the Cloudinary Java library, you have to set at least your `cloud_name`. An `api_key` and `api_secret` are also needed for secure API calls to Cloudinary (e.g., image and video uploads).

You can set the configuration parameters globally using one of the options shown below, or programmatically in each call to a Cloudinary method. Parameters set in a call to a Cloudinary method override globally set parameters.

> **NOTES**:
>
> * The JSP tag library requires a Cloudinary instance to be available in the **Singleton** to function correctly. Use [Option 1](#option_1_environment_variable_configuration_with_singleton_) or [Option 3](#option_3_manual_singleton_registration) if you're working with JSP tags.

> * For backward compatibility reasons, the default value of the optional `secure` configuration parameter is `false`. However, for most modern applications, it's recommended to configure the `secure` parameter to `true` to ensure that your transformation URLs are always generated as HTTPS.

#### Option 1: Environment variable configuration (with Singleton)
To define the `CLOUDINARY_URL` environment variable:

1. Copy the **API environment variable** format from the [API Keys](https://console.cloudinary.com/app/settings/api-keys) page of the Cloudinary Console Settings. 
2. Replace `<your_api_key>` and `<your_api_secret>` with your actual values. Your cloud name is already correctly included in the format. 
 
For example:

```
CLOUDINARY_URL=cloudinary://my_key:my_secret@my_cloud_name
```
Once the environment variable is configured, retrieve a Cloudinary singleton instance in your code. This is the recommended option if you're using JSP tag libraries, as they require an instance to be available in the **Singleton**.

```java
Cloudinary cloudinary = Singleton.getCloudinary();
```

#### Option 2: Direct instance creation

Create a Cloudinary instance directly with your configuration parameters. 

This approach creates a regular instance without using the singleton pattern. Use this for simple applications where you don't need JSP tag library support.

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

#### Option 3: Manual singleton registration

If you need to manually register a Cloudinary instance as a singleton (for example, when using JSP tag libraries without environment variables):

```java
import com.cloudinary.*;
...
// First create your Cloudinary instance
Cloudinary myCloudinary = new Cloudinary(ObjectUtils.asMap(
"cloud_name", "my_cloud_name",
"api_key", "my_api_key",
"api_secret", "my_api_secret",
"secure", true));

// Then register it as the singleton
SingletonManager manager = new SingletonManager();
manager.setCloudinary(myCloudinary);
manager.init();
```

> **TIP**: You may also want to check out the [API Keys and Credentials](finding_your_credentials_tutorial) video tutorial.

### Set additional configuration parameters

In addition to the required configuration parameters, you can define a number of optional [configuration parameters](cloudinary_sdks#configuration_parameters) if relevant.

The following example shows appending `secure_distribution` and `upload_prefix` to the environment variable:

```
CLOUDINARY_URL=cloudinary://my_key:my_secret@my_cloud_name?secure_distribution=mydomain.com&upload_prefix=https://api-eu.cloudinary.com/
```

## Use

Once you've installed and configured the Java SDK, [import the package](#import_the_package) and then you can use it for:
* **Uploading files to your product environment**: You can upload any files, not only images and videos, set your own naming conventions and overwrite policies, moderate and tag your assets on upload, and much more. [See&nbsp;example](#quick_example_file_upload)
* **Transforming and optimizing images and videos**: Keeping your original assets intact in your product environment, you can deliver different versions of your media - different sizes, formats, with effects and overlays, customized for your needs. [See&nbsp;example](#quick_example_transform_and_optimize)
* **Managing assets**: Using methods from the Admin and Upload APIs, you can organize your assets, for example, list, rename and delete them, add tags and metadata and use advanced search capabilities. [See&nbsp;example](#quick_example_get_details_of_a_single_asset)

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`

### Import the package

When using in Java code, import the package:

```java
import com.cloudinary.*;
```

When using in a JSP view, import the tag library:

```java
<%@taglib uri="http://cloudinary.com/jsp/taglib" prefix="cl" %>
```

### Quick example: File upload

The following Java code uploads the `dog.mp4` video using the public\_id, `my_dog`. The video overwrites the existing `my_dog` video if it exists. When the video upload finishes, the specified notification URL receives details about the uploaded media asset.

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

> **Learn more about upload**:
>
> * Read the [Upload guide](upload_images) to learn more about customizing uploads, using upload presets and more.

> * See more examples of [image and video upload](java_image_and_video_upload) using the Cloudinary Java library.  

> * Explore the [Upload API reference](image_upload_api_reference) to see all available methods and options.

### Quick example: Transform and optimize

Take a look at the following transformation code and the image it delivers:

![sample transformation](https://res.cloudinary.com/demo/image/upload/c_thumb,g_face,h_150,w_150/r_20/e_sepia/l_cloudinary_icon/e_brightness:90/o_60/c_scale,w_50/fl_layer_apply,g_south_east,x_5,y_5/a_10/q_auto/front_face.png "secure: true, disable_all_tab: true, with_url: false, frameworks:java")

```java
cloudinary.url().transformation(new Transformation()
  .gravity("face").height(150).width(150).crop("thumb").chain()
  .radius(20).chain()
  .effect("sepia").chain()
  .overlay(new Layer().publicId("cloudinary_icon")).chain()
  .effect("brightness:90").chain()
  .opacity(60).chain()
  .width(50).crop("scale").chain()
  .flags("layer_apply").gravity("south_east").x(5).y(5).chain()
  .angle(10).chain()
  .quality("auto")).imageTag("front_face.png");
```

This relatively simple code performs all of the following on the original front_face.jpg image before delivering it:

* **Crop** to a 150x150 thumbnail using face-detection gravity to automatically determine the location for the crop
* **Round the corners** with a 20 pixel radius
* Apply a **sepia effect**
* **Overlay the Cloudinary logo** on the southeast corner of the image (with a slight offset). Scale the logo overlay down to a 50 pixel width, with increased brightness and partial transparency (opacity = 60%).
* **Rotate** the resulting image (including the overlay) by 10 degrees
* **Convert** and deliver the image in PNG format (the originally uploaded image was a JPG)
* **Optimize** the image to reduce the size of the image without impacting visual quality.

And here's the URL that's automatically generated and included in an image tag from the above code:

![sample transformation](https://res.cloudinary.com/demo/image/upload/c_thumb,g_face,h_150,w_150/r_20/e_sepia/l_cloudinary_icon/e_brightness:90/o_60/c_scale,w_50/fl_layer_apply,g_south_east,x_5,y_5/a_10/q_auto/front_face.png "secure: true, disable_all_tab: true, with_code:false, with_image:false")

In a similar way, you can [transform a video](java_video_manipulation#video_transformation_examples).

> **Learn more about transformations**:
>
> * Read the [image](image_transformations) and [video](video_manipulation_and_delivery) transformation guides to learn about the different ways to transform your assets.

> * See more examples of [image](java_image_manipulation) and [video](java_video_manipulation) transformations using the Cloudinary Java library.  

> * See all possible transformations in the [Transformation URL API reference](transformation_reference).

### Quick example: Get details of a single asset

The following Java example uses the Admin API [resource](admin_api#get_details_of_a_single_resource_by_public_id) method to return details of the image with public ID `cld-sample`:

```java
Cloudinary cloudinary = new Cloudinary();
ApiResponse getResult = cloudinary.api().resource("cld-sample", ObjectUtils.emptyMap());
```

#### Sample response

```json
{
  "asset_id": "bf98540caf22ed65775ee0951f4746c9",
  "public_id": "cld-sample",
  "format": "jpg",
  "version": 1719304891,
  "resource_type": "image",
  "type": "upload",
  "created_at": "2024-06-25T08:41:31Z",
  "bytes": 476846,
  "width": 1870,
  "height": 1250,
  "backup": true,
  "asset_folder": "",
  "display_name": "cld-sample",
  "url": "http://res.cloudinary.com/cld-docs/image/upload/v1719304891/cld-sample.jpg",
  "secure_url": "https://res.cloudinary.com/cld-docs/image/upload/v1719304891/cld-sample.jpg",
  "next_cursor": "497b323dcb9883a15a5e6a7cfb75d439e4de1ca882f5cbe8de6a8b322c37bdad",
  "derived": [
    {
      "transformation": "c_scale,w_500",
      "format": "jpg",
      "bytes": 22871,
      "id": "ce3d7bf3068809656dc5aa76572535da",
      "url": "http://res.cloudinary.com/cld-docs/image/upload/c_scale,w_500/v1719304891/cld-sample.jpg",
      "secure_url": "https://res.cloudinary.com/cld-docs/image/upload/c_scale,w_500/v1719304891/cld-sample.jpg"
    }
  ]
}

 ```

> **Learn more about managing assets**:
>
> * Check out the [Image and Video asset management](asset_management) guide for all the different capabilities.

> * Get an overview of [asset management](java_asset_administration) using the Java SDK.

> * Select the **Java** tab in the [Admin API](admin_api) and [Upload API](image_upload_api_reference) references to see example code snippets.

## Java-specific features

You can use Cloudinary's Java SDK for any Java application. However, this SDK also provides some extra Java-specific functionality:

* [JSP tag library](https://central.sonatype.com/artifact/com.cloudinary/cloudinary-taglib) to ease and facilitate the inclusion, transformation, upload, and storage in a Java EE web application
* [Server-side](java_image_and_video_upload#server_side_upload) file upload + [direct unsigned](java_image_and_video_upload#direct_uploading_from_the_browser) file upload from the browser using the jQuery plugin
* Build URLs for [image](java_image_manipulation) and [video](java_video_manipulation) transformation 
* API wrappers: [file upload](image_upload_api_reference), [administration](admin_api), [transformations](transformation_reference), and more

 
## Sample projects
Take a look at the [Java sample projects][sample-projects-link] page to help you get started integrating Cloudinary into your Java application.

> **READING**:
>
> * Try out the Java SDK using the [quick start](java_quickstart).

> * Learn more about [uploading images and videos](java_image_and_video_upload) using the Java SDK.    

> * See examples of powerful [image](java_image_manipulation) and [video](java_video_manipulation) transformations using Java code, and see our [image transformations](image_transformations) and [video transformation](video_manipulation_and_delivery) docs.   

> * Check out Cloudinary's [asset management](java_asset_administration) capabilities, for example, renaming and deleting assets, adding tags and metadata to assets, and searching for assets.

> * Stay tuned for updates by following the [Release Notes](programmable_media_release_notes) and the [Cloudinary Blog](https://cloudinary.com/blog).
 
