An async Java client library for the Supabase Storage API
The version being used supports different version of the storage API, you can find which version supports up to what version in the CHANGELOG
For installation please see the packages section, it will show you how the dependency block should look.
importio.supabase.StorageClient;
importio.supabase.api.IStorageFileAPI;
importio.supabase.data.bucket.CreateBucketResponse;
importio.supabase.data.file.*;
importjava.io.File;
importjava.util.concurrent.CompletableFuture;
importjava.util.concurrent.ExecutionException;
publicclassMain {
publicstaticvoidmain(String[] args) {
Stringurl = System.getenv("SUPABASE_URL");
StringserviceToken = System.getenv("SUPABASE_SERVICE_TOKEN");
StorageClientstorageClient = newStorageClient(serviceToken, url);
// Interact with Supabase StorageCompletableFuture<CreateBucketResponse> res = storageClient.createBucket("examplebucket");
// Do something on future completion.res.thenAccept((bucketRes) -> {
IStorageFileAPIfileAPI = storageClient.from(bucketRes.getName());
try {
// We call .get here to block the thread and retrieve the value or an exception.// Pass the file path in supabase storage and pass a file object of the file you want to upload.FilePathResponseresponse = fileAPI.upload("my-secret-image/image.png", newFile("file-path-to-image.png")).get();
// Generate a public url (The link is only valid if the bucket is public).fileAPI.getPublicUrl("my-secret-image/image.png", newFileDownloadOption(false), newFileTransformOptions(500, 500, ResizeOption.COVER, 50, FormatOption.NONE));
// Create a signed url to download an object in a private bucket that expires in 60 seconds, and will be downloaded instantly on link as "my-image.png"fileAPI.getSignedUrl("my-secret-image/image.png", 60, newFileDownloadOption("my-image.png"), null);
// Download the filefileAPI.download("my-secret-image/image.png", null);
} catch (InterruptedException | ExecutionExceptione) {
thrownewRuntimeException(e);
}
});
}
}Made with contrib.rocks.
We are more than happy to have contributions! Please submit a PR.
For testing the application you will need to spin up the docker compose found in the infra folder.
cd infra.cp .env.example .env- Fill in the values of the .env
docker compose up -d
Then you can test the application with the default values already in the test files.
