Java quick start

Last updated: Jan-03-2023

This quick start is intended to let you quickly try using several common Cloudinary features. It doesn't necessarily employ coding best practices and the code you create here isn't intended for production.

You can perform this quick start in a code sandbox or in a clean project in the dev environment of your choice.

You can also view the completed code of this quick start in a GitHub repo.

If you aren't familiar with Cloudinary, you may want to first take a look at the Developer get started guide for a high-level overview of integrating Cloudinary into your code, and an introduction to the main concepts.

You may also find our Glossary helpful to understand Cloudinary-specific terminology.


To perform the steps in this quick start, you'll need:

1. Set up and configure the library

Add the cloudinary and dotenv dependencies to the list of dependencies in pom.xml:


Copy to clipboard

Then, in your project, create a file called .env and add the following line with your Cloudinary environment variable (replace cloudinary://<API_KEY>:<API_SECRET>@<CLOUD_NAME> below with your own environment variable value):


Copy to clipboard
// Copy and paste your API environment variable


When writing your own applications, follow your organization's policy on storing secrets and don't expose your API secret.

In your code, include the following Cloudinary libraries as well as the dotenv library in your project. Copy and paste the following code into your file:

Copy to clipboard
// Import the required packages

import com.cloudinary.*;
import com.cloudinary.utils.ObjectUtils;
import io.github.cdimascio.dotenv.Dotenv;

import java.util.Map;

You can now load your Cloudinary credentials from your .env file as shown below. Copy and paste the following code into your Main class: (continued)

Copy to clipboard
// Set your Cloudinary credentials

Dotenv dotenv = Dotenv.load();
Cloudinary cloudinary = new Cloudinary(dotenv.get("CLOUDINARY_URL")); = true;

2. Upload an image

Copy and paste the following code into a try block within your Main class: (continued)

Copy to clipboard
// Upload the image
Map params1 = ObjectUtils.asMap(
    "use_filename", true,
    "unique_filename", false,
    "overwrite", true

        cloudinary.uploader().upload("", params1));

3. Get details of the image (continued)

Copy to clipboard
// Get the asset details
Map params2 = ObjectUtils.asMap(
        "quality_analysis", true

        cloudinary.api().resource("coffee_cup", params2));

4. Transform the uploaded image (continued)

Copy to clipboard
// Create the image tag with the transformed image and log it to the console
        cloudinary.url().transformation(new Transformation()

// The code above generates an HTML image tag similar to the following:
//  <img src=',c_pad,h_400,w_300/coffee_cup' height='400' width='300'/>

5. Run your code

Run your code by clicking the Run button on the main class.

You can use the returned image tag to display the image on your website. For now, copy and paste the URL to see the transformed image in the browser:

Transformed coffee_cup image

View the completed code

You can find the full code example for this on GitHub.

Next steps

  • Learn more about the Java SDK by visiting the other pages in this SDK guide.
  • Get comprehensive details about Cloudinary features and capabilities:

✔️ Feedback sent!

Rate this page: