We meant it when we said that there was some exciting news coming up about our SDKs and to prove that, we'd like to give you a taste of what we have in store.

Today, we are pleased to announce the official release of our Java SDK!

Having a toast on our brand new Java SDK Having a toast on our brand new Java SDK

This SDK comes with the following features and also includes support for our recently added tus API:

  • Create an Assembly (of course). This supports tus resumable uploads, which is great for when you are uploading large files on an unreliable network.
  • Get an Assembly
  • Cancel the execution of an Assembly
  • List Assemblies
  • Create a Template
  • Update a Template
  • Delete a Template
  • List Templates
  • Get a Template
  • Get the monthly bill for your account

Here are a few quick steps to help you get started:

1. Install the SDK by downloading it manually from Maven Central Search, or you can install it from our Maven and Jcenter repositories.

Gradle:

compile 'com.transloadit.sdk:transloadit:0.0.3'

Maven:

<dependency>
  <groupId>com.transloadit.sdk</groupId>
  <artifactId>transloadit</artifactId>
  <version>0.0.3</version>
</dependency>

2. Create an Example class, instantiating the Transloadit client within it. This will require you to enter your API credentials:

import com.transloadit.sdk.Transloadit;

public class Example {

  public static void main(String[] args) {
    Transloadit transloadit = new Transloadit("YOUR_TRANSLOADIT_KEY", "YOUR_TRANSLOADIT_SECRET");
  }
}

3. Create a new Assembly instance and add the file that you want to upload, along with the Assembly Steps and Instructions, in order to process it. After doing so, your updated class should look like this:

import com.transloadit.sdk.Transloadit;
import java.io.File;
import java.util.HashMap;

public class Main {

  public static void main(String[] args) {
    Transloadit transloadit = new Transloadit("YOUR_TRANSLOADIT_KEY", "YOUR_TRANSLOADIT_SECRET");

    Assembly assembly = transloadit.newAssembly();

    Map<String, Object> stepOptions = new HashMap<>();
    stepOptions.put("width", 75);
    stepOptions.put("height", 75);
    assembly.addStep("resize", "/image/resize", stepOptions);

    assembly.addFile(new File("PATH/TO/FILE.jpg"));
  }
}

4. Submit the Assembly to Transloadit by calling the save method. This method enables tus' resumable uploads by default. Our updated Example class should now look like this:

import com.transloadit.sdk.Transloadit;
import com.transloadit.sdk.exceptions.LocalOperationException;
import com.transloadit.sdk.exceptions.RequestException;
import com.transloadit.sdk.response.AssemblyResponse;
import java.io.File;
import java.util.HashMap;

public class Main {

  public static void main(String[] args) {
    Transloadit transloadit = new Transloadit("YOUR_TRANSLOADIT_KEY", "YOUR_TRANSLOADIT_SECRET");

    Assembly assembly = transloadit.newAssembly();

    Map<String, Object> stepOptions = new HashMap<>();
    stepOptions.put("width", 75);
    stepOptions.put("height", 75);
    assembly.addStep("resize", "/image/resize", stepOptions);

    assembly.addFile(new File("PATH/TO/FILE.jpg"));
    try {
      AssemblyResponse response = assembly.save();
    } catch (RequestException | LocalOperationException e) {
      // handle exception here
      e.printStackTrace();
    }
  }
}

5. Because we want to wait until the Assembly execution is completed before viewing the result, we will now add one more snippet to make the class look like this:

import com.transloadit.sdk.Transloadit;
import com.transloadit.sdk.exceptions.LocalOperationException;
import com.transloadit.sdk.exceptions.RequestException;
import com.transloadit.sdk.response.AssemblyResponse;
import java.io.File;
import java.util.HashMap;

public class Main {

  public static void main(String[] args) {
    Transloadit transloadit = new Transloadit("YOUR_TRANSLOADIT_KEY", "YOUR_TRANSLOADIT_SECRET");

    Assembly assembly = transloadit.newAssembly();

    Map<String, Object> stepOptions = new HashMap<>();
    stepOptions.put("width", 75);
    stepOptions.put("height", 75);
    assembly.addStep("resize", "/image/resize", stepOptions);

    assembly.addFile(new File("PATH/TO/FILE.jpg"));
    try {
      AssemblyResponse response = assembly.save();
      // wait for assembly to finish executing.
      while (!response.isFinished()) {
        response = transloadit.getAssemblyByUrl(response.getSslUrl());
      }
      String resultUrl = response.getStepResult("resize").getJSONObject(0).getString("url");
      System.out.println("Here's your assembly result: " + resultUrl);
    } catch (RequestException | LocalOperationException e) {
      // handle exception here
      e.printStackTrace();
    }
  }
}

And there you have it! It's that easy to get our new Java SDK up and running. 😄

For more detailed documentation and examples, please take a look at:

We hope you will enjoy our new release. Stay tuned for more!