Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/supabase-community/storage-java
A Java client library for the Supabase Storage API
https://github.com/supabase-community/storage-java
java supabase supabase-storage
Last synced: 3 months ago
JSON representation
A Java client library for the Supabase Storage API
- Host: GitHub
- URL: https://github.com/supabase-community/storage-java
- Owner: supabase-community
- License: mit
- Created: 2022-12-07T18:47:49.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-16T11:25:33.000Z (4 months ago)
- Last Synced: 2024-11-02T15:27:38.149Z (3 months ago)
- Topics: java, supabase, supabase-storage
- Language: Java
- Homepage: https://supabase-community.github.io/storage-java/
- Size: 630 KB
- Stars: 14
- Watchers: 3
- Forks: 1
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# storage-java
An async Java client library for the [Supabase Storage API](https://github.com/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](./CHANGELOG.md)
## Installation
For installation please see the [packages](https://github.com/supabase-community/storage-java/packages) section, it will show you how the dependency block should look.## Example
```java
import io.supabase.StorageClient;
import io.supabase.api.IStorageFileAPI;
import io.supabase.data.bucket.CreateBucketResponse;
import io.supabase.data.file.*;import java.io.File;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;public class Main {
public static void main(String[] args) {
String url = System.getenv("SUPABASE_URL");
String serviceToken = System.getenv("SUPABASE_SERVICE_TOKEN");StorageClient storageClient = new StorageClient(serviceToken, url);
// Interact with Supabase Storage
CompletableFuture res = storageClient.createBucket("examplebucket");// Do something on future completion.
res.thenAccept((bucketRes) -> {
IStorageFileAPI fileAPI = 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.
FilePathResponse response = fileAPI.upload("my-secret-image/image.png", new File("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", new FileDownloadOption(false), new FileTransformOptions(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, new FileDownloadOption("my-image.png"), null);// Download the file
fileAPI.download("my-secret-image/image.png", null);} catch (InterruptedException | ExecutionException e) {
throw new RuntimeException(e);
}
});
}
}```
## Package made possible through the efforts of:
Made with [contrib.rocks](https://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.