Every time a file gets uploaded its file name, size and client-side mime type are included with its contents. Loom provides a common interface to access any request parameter, be it a file or not, using LoomServletRequest.getParam(String paramName). This method can return an instance of StringParam or FileParam. These classes are the low-API to access uploaded file data, and can be used by users who wish to handle uploaded files by themselves.
Loom includes automatic binding of uploaded files to:
PersistentFile is an useful abstraction that may be used for uploaded files, download files, or injected as a spring Resource (using PersistentFileResource). While persisting, the file contents get separated depending on your persistence strategy:
Keeping the file metadata and its contents separated allows for flexible file management, keeping a list of files in the database and their content in some system folder, for example. It also is an effective workaround for handling large persistent files, since hibernate ignores FetchType.LAZY in blob properties.
You can use one of the default FileManager implementation classes or roll your own.
Note that there is no JPA relationship between a PersistentFile and its contents. To get the contents, you should invoke fileManager.find() for each file.
Delivering persistent files from the server is quite easy:
public class FilesAction extends AbstractAction {
@Injected
private FileManager fileManager;
/** the id of the file to be retrieved */
private Integer id;
@Path("/{id}")
public Resolution getFile() {
return send(fileManager.find(id));
}
}