Class StorageClient


  • public class StorageClient
    extends Object

    Provides a Storage API client.

    The example below illustrates the Storage API.

    
      import io.nitric.api.storage.StorageClient;
      ...
    
      // Create a storage client with the bucket name 'inspection-images'
      var client = StorageClient.build("inspection-images");
    
      // Store an image file
      String imageKey = "582764-front-elevation.jpg"
      byte[] imageData = ...
      client.write(imageKey, imageData);
      ...
    
      // Load an image file
      imageKey = "582764-side-elevation.jpg"
      imageData = client.read(imageKey, imageData);
      ...
    
      // Delete an image file
      imageKey = "582764-rear-elevation.jpg"
      client.delete(imageKey);
     
    Since:
    1.0
    • Method Detail

      • read

        public byte[] read​(String key)
        Retrieve an item from a bucket with the given key if it exists.
        Parameters:
        key - the access key for the storage bucket item (required)
        Returns:
        the storage item data is it exists, or null otherwise
      • write

        public void write​(String key,
                          byte[] data)
        Store an item to a bucket with the given key. This operation will perform a create or update depending upon whether an item already exists in the bucket for the given key.
        Parameters:
        key - the key for the bucket item (required)
        data - the item data
      • delete

        public void delete​(String key)
        Delete an item from a bucket with the given key if it exists.
        Parameters:
        key - the key for the bucket item (required)
      • newBuilder

        public static StorageClient.Builder newBuilder()
        Create an new StorageClient builder.
        Returns:
        new StorageClient builder
      • build

        public static StorageClient build​(String bucket)
        Return a new StorageClient with the specified bucket name.
        Parameters:
        bucket - the bucket name (required)
        Returns:
        a new StorageClient with the specified bucket name
      • toString

        public String toString()
        Overrides:
        toString in class Object
        Returns:
        the string representation of this object