uploadcare-java
This is a Java library for Uploadcare.
Supported features:
- Complete file and project API v2
- Paginated resources fetched as
List<T>
- CDN path builder
- File uploads from disk, byte array, and URL
Maven
Latest stable version is available from Maven Central.
To include it in your build, add this to the <dependencies />
section
of the project's pom.xml file:
<dependency>
<groupId>com.uploadcare</groupId>
<artifactId>uploadcare</artifactId>
<version>1.0</version>
</dependency>
Examples
Basic API Usage
Client client = new Client("publickey", "privatekey");
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.isMadePublic()) {
published.add(file.getOriginalFileUrl());
}
}
See documentation for details:
Building CDN URLs
File file = client.getFile("85b5644f-e692-4855-9db0-8c5a83096e25");
CdnPathBuilder builder = file.cdnPath()
.resizeWidth(200)
.cropCenter(200, 200)
.grayscale();
URI url = Urls.cdn(builder);
See documentation for details:
File uploads
Client client = Client.demoClient();
java.io.File file = new java.io.File("olympia.jpg");
Uploader uploader = new FileUploader(client, sourceFile);
try {
File file = uploader.upload().save();
System.out.println(file.getOriginalFileUrl());
} catch (UploadFailureException e) {
System.out.println("Upload failed :(");
}
See documentation for details: