Package io.nitric.api.storage
Class StorageClient
- java.lang.Object
-
- io.nitric.api.storage.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StorageClient.Builder
Provides a StorageClient Builder.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StorageClient
build(String bucket)
Return a new StorageClient with the specified bucket name.void
delete(String key)
Delete an item from a bucket with the given key if it exists.static StorageClient.Builder
newBuilder()
Create an new StorageClient builder.byte[]
read(String key)
Retrieve an item from a bucket with the given key if it exists.String
toString()
void
write(String key, byte[] data)
Store an item to a bucket with the given key.
-
-
-
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
-
-