Class RestFileStorage

java.lang.Object
io.jmix.restds.filestorage.RestFileStorage
All Implemented Interfaces:
FileStorage, org.springframework.beans.factory.InitializingBean

public class RestFileStorage extends Object implements FileStorage, org.springframework.beans.factory.InitializingBean
File storage implementation that complements RestDataStore by the ability to store and load files using the generic REST /files endpoints.

To use RestFileStorage, define the following bean in your application:

     @Bean
     FileStorage backendFileStorage() {
         return new RestFileStorage("backend", "fs");
     }
 
In this example, 'backend' is the name of REST DataStore representing the remote application and 'fs' is the name of the corresponding file storage in the remote application.

See RestFileStorage(String, String) for more information.

  • Constructor Details

    • RestFileStorage

      public RestFileStorage(String restDataStoreName, String remoteStorageName)
      Constructor.
      Parameters:
      restDataStoreName - name of the REST DataStore that represents the remote application
      remoteStorageName - name of the corresponding file storage in the remote application, e.g. 'fs' for local file storage
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • getStorageName

      public String getStorageName()
      Description copied from interface: FileStorage
      Returns the name of this storage, which will be saved in FileRefs.

      Each file storage in the application should have a unique name.

      Specified by:
      getStorageName in interface FileStorage
    • getRemoteStorageName

      public String getRemoteStorageName()
      Returns:
      name of the corresponding file storage in the remote application, e.g. 'fs' for local file storage
    • saveStream

      public FileRef saveStream(String fileName, InputStream inputStream, Map<String,Object> parameters)
      Description copied from interface: FileStorage
      Saves an InputStream contents into the file storage using additional parameters.
      Specified by:
      saveStream in interface FileStorage
      Parameters:
      fileName - file name
      inputStream - input stream, must be closed in the calling code
      parameters - additional parameters that can be used in specific storage implementation (for example, can be converted to FileRef parameters)
      Returns:
      file reference
    • openStream

      public InputStream openStream(FileRef reference)
      Description copied from interface: FileStorage
      Returns an input stream to load a file contents.
      Specified by:
      openStream in interface FileStorage
      Parameters:
      reference - file reference
      Returns:
      input stream, must be closed after use
    • removeFile

      public void removeFile(FileRef reference)
      Description copied from interface: FileStorage
      Removes a file from the file storage.
      Specified by:
      removeFile in interface FileStorage
      Parameters:
      reference - file reference
    • fileExists

      public boolean fileExists(FileRef reference)
      Description copied from interface: FileStorage
      Tests whether the file denoted by this file reference exists.
      Specified by:
      fileExists in interface FileStorage
      Parameters:
      reference - file reference
      Returns:
      true if the file denoted by this file reference exists