Package io.jmix.restds.filestorage
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionRestFileStorage(String restDataStoreName, String remoteStorageName) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanfileExists(FileRef reference) Tests whether the file denoted by this file reference exists.Returns the name of this storage, which will be saved inFileRefs.openStream(FileRef reference) Returns an input stream to load a file contents.voidremoveFile(FileRef reference) Removes a file from the file storage.saveStream(String fileName, InputStream inputStream, Map<String, Object> parameters) Saves an InputStream contents into the file storage using additional parameters.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.jmix.core.FileStorage
saveStream
-
Constructor Details
-
RestFileStorage
Constructor.- Parameters:
restDataStoreName- name of the REST DataStore that represents the remote applicationremoteStorageName- 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:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
getStorageName
Description copied from interface:FileStorageReturns the name of this storage, which will be saved inFileRefs.Each file storage in the application should have a unique name.
- Specified by:
getStorageNamein interfaceFileStorage
-
getRemoteStorageName
- Returns:
- name of the corresponding file storage in the remote application, e.g. 'fs' for local file storage
-
saveStream
Description copied from interface:FileStorageSaves an InputStream contents into the file storage using additional parameters.- Specified by:
saveStreamin interfaceFileStorage- Parameters:
fileName- file nameinputStream- input stream, must be closed in the calling codeparameters- additional parameters that can be used in specific storage implementation (for example, can be converted to FileRef parameters)- Returns:
- file reference
-
openStream
Description copied from interface:FileStorageReturns an input stream to load a file contents.- Specified by:
openStreamin interfaceFileStorage- Parameters:
reference- file reference- Returns:
- input stream, must be closed after use
-
removeFile
Description copied from interface:FileStorageRemoves a file from the file storage.- Specified by:
removeFilein interfaceFileStorage- Parameters:
reference- file reference
-
fileExists
Description copied from interface:FileStorageTests whether the file denoted by this file reference exists.- Specified by:
fileExistsin interfaceFileStorage- Parameters:
reference- file reference- Returns:
- true if the file denoted by this file reference exists
-