Application servers may store uploaded files in the server's file system and persist only the file paths in a database. Obtaining a consistent backup of such a dataset may be difficult.
This sample project uses Spring, JPA and Hibernate ORM to store uploaded files as BLOBs in a database. MySQL supports 4GB BLOBs, H2 at least 16GB BLOBs and PostgreSQL even 4TB BLOBs. BLOBs are never materialized in memory.
Using BLOBs for file storage can be advantageous since this keeps the complete dataset in a single place (the database); this provides for consistent backups and synchronization in a database cluster.
Within this project, a few additional techniques are mentioned that might be useful.
- Uploading files and storing them as BLOBs with Spring, JPA and Hibernate ORM
- Serving and downloading uploaded files
- Hiding primary keys from clients and identifying file entities by UUID
- Using a mapped superclass as base class for entity classes
- Applying joined table inheritance to derive specialized file entities (such as image entities)
- Generating image thumbnails with the Imagick PHP extension
- Rendering a UI with the JSP