> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://uploadcare.com/docs/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://uploadcare.com/docs/_mcp/server.

# Java API Client

> Java Uploadcare API client for Fast & Reliable File Uploads; File, Group, Project Operations & More.

Java integration handles uploads and file operations by wrapping Uploadcare
[Upload API](https://uploadcare.com/docs/api/upload/) and [REST API](https://uploadcare.com/docs/api/rest/). This
comprehensive API client lets you use most of the Uploadcare features from within
your Java app.

[GitHub →](https://github.com/uploadcare/uploadcare-java/)

## Features

Uploading ([Upload API](https://uploadcare.com/docs/api/upload/)):

* Upload files from local storage and URLs (up to 5 TB)
* Multipart uploading for large files
* Uploading network to speed uploading jobs (like CDN)

File management ([REST API](https://uploadcare.com/docs/api/rest/)):

* Get file info and perform various operations (store/delete/copy) with them
* Work with groups of files
* Get info about account project
* Manage webhooks
* Paginated resources are fetched as `List<T>`
* CDN path builder

Image processing ([URL API](https://uploadcare.com/docs/api/url/)):

* Compression
* Geometry
* Colors
* Definition
* Image and text overlays
* Rotations
* Recognition
* File info
* Proxy (fetch)

Security features:

* Secure authentication
* Secure uploads (signed uploads)

## Requirements \[#sign-up]

* [Uploadcare account](https://app.uploadcare.com/accounts/signup/)
* [Java JDK](https://www.oracle.com/java/technologies/downloads#java11)

Go to your Uploadcare [Dashboard](https://app.uploadcare.com/) and create a new project for your
Java app. It'll have [API keys](https://app.uploadcare.com/projects/-/api-keys/) to complete Java API client
integration.

## Setup

The latest stable library version is available at [Maven Central](https://search.maven.org/artifact/com.uploadcare/uploadcare).

Include the following code into your build by adding the following dependencies
into `pom.xml` for your project.

```xml
<dependency>
  <groupId>com.uploadcare</groupId>
  <artifactId>uploadcare</artifactId>
  <version>3.5.3</version>
</dependency>
```

To build with Gradle add to Gradle build file:

```groovy
implementation 'com.uploadcare:uploadcare:3.5.3'
```

> **Note**
>
> **Note:** This guide covers uploadcare-java v3.5.3 which uses REST API v0.6. Support for REST API v0.7 (including `getMetadata()`, `getContentInfo()`, and `getAppData()`) is under development.

## Usage example

### Create `Client` and basic API usage \[#client-init]

Use your [Public](/docs/start/settings/#keys-public) and [Secret](/docs/start/settings/#keys-secret) API
Keys from the Java project's dashboard.

Create a new API Client:

```java
Client client = new Client("YOUR_PUBLIC_KEY", "YOUR_SECRET_KEY");
Project project = client.getProject();
Project.Collaborator owner = project.getOwner();

List<URI> published = new ArrayList<URI>();
Iterable<File> files = client.getFiles().asIterable();
for (File file : files) {
    if (file.hasOriginalFileUrl()) {
        published.add(file.getOriginalFileUrl());
    }
}
```

### Building CDN URLs

Uploadcare CDN can process images by adding directives like this:

```cdn
https://1gkkwxp4lp.ucarecd.net/85b5644f-e692-4855-9db0-8c5a83096e25/-/resize/640x640/image.jpg
```

Here's a Java example to automate CDN URL creation:

```java
File file = client.getFile("85b5644f-e692-4855-9db0-8c5a83096e25");
CdnPathBuilder builder = file.cdnPath()
        .resizeWidth(200)
        .cropCenter(200, 200)
        .grayscale();
URI url = Urls.cdn(builder);
```

### Upload files with `FileUploader` and `UrlUploader` \[#uploader]

Check out two options to upload files with the Java Uploadcare library
`Uploader` interface.

Upload with [UrlUploader](http://uploadcare.github.io/uploadcare-java/apidocs/com/uploadcare/upload/UrlUploader):

```java
Uploader uploader = new UrlUploader(client, "https://example.com/image.jpg");
File file = uploader.upload();
System.out.println(file.getFileId());
System.out.println(file.getOriginalFileUrl());
```

Upload with [FileUploader](http://uploadcare.github.io/uploadcare-java/apidocs/com/uploadcare/upload/FileUploader) by providing `java.io.File`:

```java
java.io.File localFile = new java.io.File("/path/to/file.jpg");
Uploader uploader = new FileUploader(client, localFile);
File file = uploader.upload();
System.out.println(file.getFileId());
System.out.println(file.getOriginalFileUrl());
```

## More upload options

#### Upload from bytes or stream

```java
// From byte array
byte[] bytes = Files.readAllBytes(Paths.get("/path/to/file.jpg"));
Uploader bytesUploader = new FileUploader(client, bytes, "file.jpg");
File bytesFile = bytesUploader.upload();

// From InputStream
InputStream stream = new FileInputStream("/path/to/file.jpg");
Uploader streamUploader = new FileUploader(client, stream, "file.jpg");
File streamFile = streamUploader.upload();
```

#### Signed uploads

```java
Uploader uploader = new FileUploader(client, localFile);
uploader.signedUpload("YOUR_SIGNATURE", "YOUR_EXPIRE_TIMESTAMP");
File file = uploader.upload();
```

> **Warning**
>
> **Warning:** Generate the signature and expire timestamp on your backend. See [signed uploads documentation](https://uploadcare.com/docs/security/secure-uploads/) for implementation details.

#### Batch file operations

```java
// Store multiple files
List<String> fileIds = Arrays.asList("UUID_1", "UUID_2", "UUID_3");
client.saveFiles(fileIds);

// Delete multiple files
client.deleteFiles(fileIds);
```

### Manage project data and files \[#project-and-files]

With `Client`, you get a few utility methods to retrieve and handle the
project-specific data, like fetching a file by a file id or listing all uploaded
files for the project. Note, *ids* are Uploadcare [UUIDs](/docs/uploads/)
associated with files whenever they get uploaded.

Here’s a short example of navigating your files and retrieving 10 file names
uploaded to your project after today’s midnight and matching some arbitrary
pattern:

```java
// Print 10 file names uploaded after today's midnight and matching regexp
client.getFiles().asList()
        .stream()
        .map(f -> new Pair<>(f.getOriginalFilename(), f.getUploadDate()))
        .filter(p -> p.getValue().after(Date.from(todayMidnight))
                && p.getKey().matches(FILENAME_STARTING_WITH_LETTERS_AND_HAVING_EXTENSION))
        .limit(10)
        .forEach(System.out::println);
```

### Automatic File Storing \[#auto-storing-mode]

When **Automatic File Storing** in [storage settings](/docs/uploads/storage/#file-storing-behavior)
is on (default), all newly uploaded files will be stored permanently. If it's
switched off, all incoming files will be deleted in 24 hours to prevent your
storage cluttering.

With **Automatic File Storing.** turned off, you can still `store` files
selectively via API. In Java, these per-file controls are provided by both
`com.uploadcare.api.Client#saveFile` taking a UUID as a parameter and
`com.uploadcare.api.File#save`.

### Transfer files to Amazon S3 \[#custom-storage]

You can connect an Amazon S3 Bucket to your Uploadcare account as custom
storage for specific [cases](/docs/s3-integration/). See [S3 storage docs](/docs/s3-integration/#storage-custom-setup)
on how to configure it.

With the Java library, you can copy files to S3 storage using the copy methods on `Client`. You can do the same via [`remote_copy` REST API](https://uploadcare.com/docs/api/rest/file/create-remote-copy).

```java
// Copy to Uploadcare local storage
CopyFile localCopy = client.copyFileLocalStorage("YOUR_FILE_UUID", true);

// Copy to custom remote storage
CopyFile remoteCopy = client.copyFileRemoteStorage("YOUR_FILE_UUID", "YOUR_STORAGE_NAME", true, null);
```

### More examples \[#conclusion]

Refer the [GitHub](https://github.com/uploadcare/uploadcare-java/) and
check out [more java examples](https://github.com/uploadcare/uploadcare-java/tree/master/example).

## Full documentation

Read the full documentation on [GitHub](https://github.com/uploadcare/uploadcare-java/).

## Related guides

* Integration with [Android](/docs/integrations/android/)