Class File


  • public class File
    extends Object

    Provides a Storage API bucket class.

    The example below illustrates the Storage API.

    
      import io.nitric.api.storage.Storage;
      ...
    
      byte[] frontData = ...
    
      // Store an file file
      Storage.bucket("inspection-images")
         .file("582764-front-elevation.jpg")
         .write(frontData);
    
      // Retrieve an image file
      byte[] sideData = Storage.bucket("inspection-images")
          .file("582764-side-elevation.jpg")
          .read();
    
      // Delete an image file
      Storage.bucket(bucket)
          .file("582764-rear-elevation.jpg")
          .delete();
     
    • Method Detail

      • getBucket

        public String getBucket()
        Return the storage bucket name.
        Returns:
        the bucket name
      • getKey

        public String getKey()
        Return the storage file key.
        Returns:
        the file key
      • read

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

        public void write​(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:
        data - the item data
      • delete

        public void delete()
        Delete an item from a bucket with the given key if it exists.
      • toString

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