3.10.8. File Storage
File storage enables uploading, storing and downloading arbitrary files associated with the entities. In the standard implementation, the files are stored outside of the main database using a specialized structure within the file system.
File storage mechanism includes the following parts:
FileDescriptorentity – the descriptor of the uploaded file (not to be confused with
java.io.FileDescriptor) enables referencing the file from the data model objects.
FileStorageAPIinterface – provides access to the file storage at the middle tier. Its main methods are:
saveStream()– saves the contents of the file passed as the
InputStreamaccording to the specified
openStream()– returns the contents of the file defined by the
FileDescriptorin the form of an opened
FileUploadControllerclass – a Spring MVC controller, which enables sending files from the Client to the Middleware with HTTP POST requests.
FileDownloadControllerclass – Spring MVC controller which enables retrieving files from the Middleware to the Client with HTTP GET requests.
FileUpload and FileMultiUpload visual components – enable uploading files from the user’s computer to the client tier of the application and then transferring them to the Middleware.
FileUploadingAPIinterface – temporary storage for files uploaded to the client tier. It is used for uploading files to the client tier by the visual components mentioned above. The application code can use
putFileIntoStorage()method for moving a file into the persistent storage of the Middleware.
FileLoader - an interface for working with the file storage using the same set of methods on both middle and client tiers.
ExportDisplay– client tier interface allowing downloading various application resources to the user’s computer. Files can be retrieved from persistent storage using the
show()method, which requires a
FileDescriptor. An instance of
ExportDisplaymay be obtained either by calling the
AppConfig.createExportDisplay()static method, or through injection into the controller class.
File transfer between the user’s computer and the storage in both directions is always performed by copying data between input and output streams. Files are never fully loaded into memory at any application level, which enables transferring files of almost any size.