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 TypeMethodDescriptionvoid
boolean
fileExists
(FileRef reference) Tests whether the file denoted by this file reference exists.Returns the name of this storage, which will be saved inFileRef
s.openStream
(FileRef reference) Returns an input stream to load a file contents.void
removeFile
(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, wait
Methods 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:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
getStorageName
Description copied from interface:FileStorage
Returns the name of this storage, which will be saved inFileRef
s.Each file storage in the application should have a unique name.
- Specified by:
getStorageName
in 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:FileStorage
Saves an InputStream contents into the file storage using additional parameters.- Specified by:
saveStream
in 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:FileStorage
Returns an input stream to load a file contents.- Specified by:
openStream
in interfaceFileStorage
- Parameters:
reference
- file reference- Returns:
- input stream, must be closed after use
-
removeFile
Description copied from interface:FileStorage
Removes a file from the file storage.- Specified by:
removeFile
in interfaceFileStorage
- Parameters:
reference
- file reference
-
fileExists
Description copied from interface:FileStorage
Tests whether the file denoted by this file reference exists.- Specified by:
fileExists
in interfaceFileStorage
- Parameters:
reference
- file reference- Returns:
- true if the file denoted by this file reference exists
-