Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

73 Commits

Repository files navigation

storage-java

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

Installation

For installation please see the packages section, it will show you how the dependency block should look.

Example

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

Package made possible through the efforts of:

Made with contrib.rocks.

Contributing

We are more than happy to have contributions! Please submit a PR.

Local development

For testing the application you will need to spin up the docker compose found in the infra folder.

  1. cd infra.
  2. cp .env.example .env
  3. Fill in the values of the .env
  4. docker compose up -d

Then you can test the application with the default values already in the test files.

About

A Java client library for the Supabase Storage API

Topics

Resources

Code of conduct

Contributing

Stars

25 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages