Upload parameters - SoKnight/ImgBB-Java-SDK GitHub Wiki

Introduction

This page describes an uploading parameters wrapped in the UploadParameters class.

Builder

You must use the UploadParameters.Builder to build a new parameters.

It is default structurized java builder with build() method which returns a configured UploadParameters instance:

UploadParameters params = new UploadParameters.Builder()
        .build();

To modify required and optional parameters you can use next builder methods:

  • [REQUIRED] .apiKey("YOUR API KEY") - Specifies the API key parameter.
  • [REQUIRED] .imageBase64("BASE64 ENCODED IMAGE") - Specifies the image parameter encoded in base64.
  • .imageName("NAME OF IMAGE") - Specifies the remote image name parameter (just name, withoul a file extension).
  • .expirationTime(ExpirationTime) - Specifies the URLs expiration time as ExpirationTime instance.
UploadParameters params = new UploadParameters.Builder()
        .apiKey("API KEY")
        .imageBase64("IMAGE BASE64")
        .imageName("rose")
        .expirationTime(ExpirationTime.fromLong(60))
        .build();

Image to Base64 converting

I was write about imageBase64 parameter which requires an image encoded as base64 string.

So you can get this base64 using special utility named as ImageBase64Converters.

This class provides three static methods and two converters, see information about it below.

BufferedImage -> Base64

This converter located in fromBufferedImage(image, formatName) method and provides easily converting a BufferedImage to Base64.

BufferedImage image = ...;
String base64 = ImageBase64Converters.fromBufferedImage(image, "png"); // "png" is an image format name

File -> Base64

This converter located in fromImageFile(file) method and provides easily converting an image File to Base64.

File file = new File("...");
String base64 = ImageBase64Converters.fromImageFile(file);

Expiration time

I also write about expirationTime parameter above which represented by ExpirationTime class.

This class will store a time value as long and provide easily ways to get this value as long or as string.

So you can create ExpirationTime instance using the next static methods:

// received value must be in the determined range: from 60 to 15552000.
ExpirationTime time = ExpirationTime.fromLong(60);
// received value must be long and be in the determined range.
ExpirationTime time = ExpirationTime.fromString("60");