Configuring Image Fields

It is possible to view, upload, replace and delete JPG and PNG image files into an entity item. There are two ways of storing a file (configuration is done in the entity class definition):

  • Directly in the database – if a field is marked with @Lob annotation.
  • On the file system – if a String field holding the file path is marked with @FileReference annotation.

Please note that for better performance of image fields processing by LightAdmin, it is advised to enable file streaming in the web.xml of your application as follows:

    <context-param>
        <param-name>light:administration:file-streaming</param-name>
        <param-value>true</param-value>
   </context-param>

Configuring Base Directory for Image Fields stored on the File System

If @FileReference annotation is specified with no parameters, the application-wide base directory will be used for the field. The directory is configured in the application’s web.xml as follows:

    <context-param>
        <param-name>light:administration:file-storage</param-name>
        <param-value>./globalBaseDirectory</param-value>
    </context-param>

Alternatively, it is possible to use field-specific directory by specifying it in the baseDirectory parameter of that field’s @FileReference annotation.

The path of the base directory may be absolute or relative to your application.

...
@Entity
public class Product {

    private String name;

    private BigDecimal price;

    @Lob
    private byte[] pictureSavedToDatabase;

    @FileReference(baseDirectory = &quot;./fieldSpecificDirectory&quot;)
    private String fileSystemPicture;

    @FileReference
    private String fileSystemPictureWithGlobalDirectory;

...

}