Skip to content

Latest commit

 

History

History
168 lines (128 loc) · 4.87 KB

File metadata and controls

168 lines (128 loc) · 4.87 KB

uploadcare-java

Build Status Maven Central Javadocs Uploadcare stack on StackShare

This is a Java library for Uploadcare.

Supported features:

  • Complete file and project APIs v0.6.
  • Paginated resources are fetched as List<T>.
  • CDN path builder.
  • File uploading from a local storage, byte arrays, URLs, and signed uploads.

The minimum requirements to build this project are:

  1. Gradle 8.2 (you can use ./gradlew or .\gradlew.bat which will download it for you).
  2. JDK 1.8 (target is 1.7, so don't use much higher version).
  3. Running ./gradlew build should run successfully.

Maven

The latest stable library version is available at Maven Central.

Include following dependency into your project's pom.xml:

<dependency>
    <groupId>com.uploadcare</groupId>
    <artifactId>uploadcare</artifactId>
    <version>3.5.2</version>
</dependency>

Gradle

Include following dependency into your project's build.gradle:

implementation 'com.uploadcare:uploadcare:3.5.1'

If you are using the kotlin style build.gradle.kts:

implementation("com.uploadcare:uploadcare:3.5.1")

Snapshot Builds (Pre-release)

Snapshot builds are published to GitHub Packages automatically:

  • From pull requests: version format {version}-PR-{pr-number}-SNAPSHOT (e.g. 3.5.3-PR-42-SNAPSHOT)
  • From the master branch: version format {version}-SNAPSHOT (e.g. 3.5.3-SNAPSHOT)

To consume a snapshot build, add the GitHub Packages repository and authenticate with a personal access token (PAT) that has read:packages scope.

Maven (snapshot)

Add to your ~/.m2/settings.xml:

<settings>
  <servers>
    <server>
      <id>uploadcare-snapshots</id>
      <username>YOUR_GITHUB_USERNAME</username>
      <password>YOUR_GITHUB_PAT</password>
    </server>
  </servers>
</settings>

Add to your pom.xml:

<repositories>
    <repository>
        <id>uploadcare-snapshots</id>
        <url>https://maven.pkg.github.com/uploadcare/uploadcare-java</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.uploadcare</groupId>
        <artifactId>uploadcare</artifactId>
        <version>3.5.3-SNAPSHOT</version>
    </dependency>
</dependencies>

Gradle (snapshot)

Add to your build.gradle (or build.gradle.kts):

repositories {
    maven {
        name = "GitHubPackages"
        url = uri("https://maven.pkg.github.com/uploadcare/uploadcare-java")
        credentials {
            username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
            password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
        }
   }
}

dependencies {
    implementation("com.uploadcare:uploadcare:3.5.3-SNAPSHOT")
}

Examples

Get your API keys to proceed with the examples below.

Read class documentation on javadoc.io.

Basic API Usage

Client client = new Client("publickey", "secretkey");
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());
    }
}

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);

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 :(");
}