Java API Client
Java integration handles uploads and file operations by wrapping Uploadcare Upload API and REST API. This comprehensive API client lets you use most of the Uploadcare features from within your Java app.
Features
Uploading (Upload API):
- 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):
- 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):
- Compression
- Geometry
- Colors
- Definition
- Image and text overlays
- Rotations
- Recognition
- File info
- Proxy (fetch)
Security features:
- Secure authentication
- Secure uploads (signed uploads)
Requirements
Go to your Uploadcare Dashboard and create a new project for your Java app. It’ll have API keys to complete Java API client integration.
Setup
The latest stable library version is available at Maven Central.
Include the following code into your build by adding the following dependencies
into pom.xml
for your project.
To build with Gradle add to Gradle build file:
Usage example
Create Client
and basic API usage
Use your Public and Secret API Keys from the Java project’s dashboard.
Create a new API Client:
Building CDN URLs
Uploadcare CDN can process images by adding directives like this:
Here’s a Java example to automate CDN URL creation:
Upload files with FileUploader
and UrlUploader
Check out two options to upload files with the Java Uploadcare library
Uploader
interface.
Upload with UrlUploader:
Upload with FileUploader by providing java.io.File
:
Note: the com.uploadcare.api.File#getOriginalFileUrl
method returns a
combination of UUID and an original file name without whitespaces.
Manage project data 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
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:
Automatic File Storing
When Automatic File Storing in storage settings 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
You can connect an Amazon S3 Bucket to your Uploadcare account as custom storage for specific cases. See custom storage docs on how to configure it.
With the Java library, you can move files to custom storage with the
com.uploadcare.api.Client#copyFile
java method. You can do
the same via remote_copy
REST API.
More examples
Refer the GitHub and check out more java examples.
Full documentation
Read the full documentation on GitHub.
Related guides
- Integration with Android