Handling Images and other File Data

For years there has been a debate about the relative merits of supporting persistent storage of images in database management systems versus file systems.

The database people think that all information should be stored and accessed using a DBMS.  The File system people think that the DBMS people are wrong -- or worse -- and that DBMS should be used for special purposes and that bulk data should be stored in a file system.

The DBMS people were clearly wrong for the first twenty or thirty years.  But as systems become larger and more powerful and as DBMS systems become more efficient and robust, the right position is not so clear.

From my perspective, particularly with respect to Web-based systems, I believe it still makes sense to store images, per se,  in the file system and store information about the images in the dbms.  The discussion that follows is based on that perspective.


Architecture

Uploading media and other file data is most likely to be done within the context of HTTP and HTML -- that is from an HTML form whose data is handled is handled in a Servlet, in a Struts Action, or in some other framework's controller.  The discussion below will assume the following architecture:

 

Two different implementations will be described.  One will use Struts, the other JavaServer Faces.

Task and Strategy

The task that will be illustrated includes the following steps.  Users upload the description of a product for an online store's catalog.  Each product description includes a small, thumbnail image (e.g., 125 pixels wide) and a larger image (e.g., 250 pixels wide).  The images are selected within a form by browsing the client's local file system.  Once selected, they are uploaded to the server as a multi-part form and handled by a control component, i.e., either a Struts Action or a Faces ManagedBean.  These components further delegate handling to a model component and a DBMS.  The database generates consecutive integers for images and stores those values as part of its product records.  However, actual images are stored in the server's file system.  The path and file name for each image are derived from the integer value generated by the DBMS using modular arithmetic.  The particular strategy used includes four levels of directories and a numeric filename with the appropriate suffix (e.g., 22.jpg).


Implementations

Struts

JavaServer Faces