Skip to main content
The official Java SDK provides a type-safe way to interact with Bunny Storage in your Java applications. Requires Java 8+.

Installation

Clone the GitHub repository and build from source. The SDK uses Jackson for JSON parsing. Add Jackson Core/Databind/Annotations as dependencies to your project.

Quickstart

Connect to your storage zone

import BCDNStorageAPI.BCDNStorage;

// Default region (Falkenstein)
BCDNStorage client = new BCDNStorage("your-storage-zone-name", "your-access-key");

// With specific region
BCDNStorage client = new BCDNStorage("your-storage-zone-name", "your-access-key", "ny");
Available regions:
Region CodeLocationCity
deFrankfurt, DEFalkenstein (default)
ukLondon, UKLondon
nyNew York, USNew York
laLos Angeles, USLos Angeles
sgSingapore, SGSingapore
seStockholm, SEStockholm
brSao Paulo, BRSao Paulo
jhJohannesburg, ZAJohannesburg
sydSydney, AUSydney

List files

import BCDNStorageAPI.BCDNObject;

BCDNObject[] files = client.getStorageObjects("remote/path/");

for (BCDNObject file : files) {
    System.out.println(file.getObjectName() + " - " + file.getLength() + " bytes");
}
Returns an array of BCDNObject objects. BCDNObject properties:
  • getGUID() - Unique identifier
  • getObjectName() - File name
  • getPath() - Directory path
  • getLength() - File size in bytes
  • getChecksum() - File checksum
  • getDateCreated() - Creation date
  • getLastChanged() - Last modification date
  • getIsDirectory() - Whether it’s a directory
  • getServerID() - Storage server ID
  • getUserID() - BunnyCDN user ID
  • getStorageZoneName() - Storage zone name
  • getStorageZoneID() - Storage zone ID
  • getReplicatedZones() - Replication regions

Upload a file

client.uploadObject("/path/to/local/file.png", "remote/path/file.png");

Upload a folder

// Upload entire folder to storage zone root
client.uploadFolder("/path/to/local/folder/", "/");

// Upload to specific remote path
client.uploadFolder("/path/to/local/folder/", "uploads/");
Empty directories will not be uploaded.

Download a file

client.downloadObject("remote/path/file.png", "/path/to/local/file.png");

Delete files

// Delete a file
client.deleteObject("remote/path/file.png");

// Delete a folder
client.deleteObject("remote/path/folder/");
Delete operations are irreversible and will succeed regardless of whether the file exists.

Examples

Basic usage

import BCDNStorageAPI.BCDNStorage;
import BCDNStorageAPI.BCDNObject;

public class Main {
    public static void main(String[] args) {
        try {
            BCDNStorage client = new BCDNStorage(
                System.getenv("STORAGE_ZONE"),
                System.getenv("STORAGE_ACCESS_KEY"),
                "de"
            );

            // List all files in root
            BCDNObject[] files = client.getStorageObjects("/");

            for (BCDNObject file : files) {
                if (file.getIsDirectory()) {
                    System.out.println("Folder: " + file.getObjectName());
                } else {
                    System.out.println("File: " + file.getObjectName());
                }
                System.out.println("- Size: " + file.getLength() + " bytes");
                System.out.println("- Last Modified: " + file.getLastChanged());
                System.out.println();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Upload and download

import BCDNStorageAPI.BCDNStorage;

public class FileOperations {
    public static void main(String[] args) {
        try {
            BCDNStorage client = new BCDNStorage(
                "my-storage-zone",
                "my-access-key",
                "de"
            );

            // Upload a file
            client.uploadObject("./local/image.png", "uploads/image.png");
            System.out.println("File uploaded successfully!");

            // Download the file
            client.downloadObject("uploads/image.png", "./downloads/image.png");
            System.out.println("File downloaded successfully!");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Batch upload folder

import BCDNStorageAPI.BCDNStorage;

public class BatchUpload {
    public static void main(String[] args) {
        try {
            BCDNStorage client = new BCDNStorage(
                "my-storage-zone",
                "my-access-key",
                "de"
            );

            // Upload entire assets folder
            client.uploadFolder("./assets/", "static/assets/");
            System.out.println("Folder uploaded successfully!");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

List and delete files

import BCDNStorageAPI.BCDNStorage;
import BCDNStorageAPI.BCDNObject;

public class CleanupOldFiles {
    public static void main(String[] args) {
        try {
            BCDNStorage client = new BCDNStorage(
                "my-storage-zone",
                "my-access-key",
                "de"
            );

            // List all files
            BCDNObject[] files = client.getStorageObjects("uploads/");

            // Delete each file
            for (BCDNObject file : files) {
                if (!file.getIsDirectory()) {
                    String filePath = "uploads/" + file.getObjectName();
                    client.deleteObject(filePath);
                    System.out.println("Deleted: " + file.getObjectName());
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Spring Boot integration

import BCDNStorageAPI.BCDNStorage;
import BCDNStorageAPI.BCDNObject;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class BunnyStorageService {

    private final BCDNStorage client;

    public BunnyStorageService(
        @Value("${bunny.storage.zone}") String storageZone,
        @Value("${bunny.storage.access-key}") String accessKey,
        @Value("${bunny.storage.region:de}") String region
    ) {
        this.client = new BCDNStorage(storageZone, accessKey, region);
    }

    public void upload(String localPath, String remotePath) throws Exception {
        client.uploadObject(localPath, remotePath);
    }

    public void download(String remotePath, String localPath) throws Exception {
        client.downloadObject(remotePath, localPath);
    }

    public BCDNObject[] list(String path) throws Exception {
        return client.getStorageObjects(path);
    }

    public void delete(String path) throws Exception {
        client.deleteObject(path);
    }
}

Resources