Giter Club home page Giter Club logo

storage-java's Introduction

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

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<CreateBucketResponse> 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.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.