Nov 9, 2021 3:34:40 PM Thomas Dumont avatar


File management service

FileService is a service for storing files.

FileService uses implementations of IFileStorageService to choose the storage mode (base, filesystem, cloud ...).

Each implementation must provide two other services: a download URL generation / reading service, a file access rights management service.

The URL management service must implement the IFileDownloadUrlService interface, and the file permissions management service must implement the IFileRBACService interface.

Several storage services can be used.

Default implementation in Lutece Core

A LocalDataBaseFileStorageService is provided by default by Lutece Core, and uses the Lutece database tables: core_file and core_physical_file. Two implementations of IFileDownloadUrlService and IFileRBACService are also provided by default.

<bean id = "defaultFileDownloadUrlService" class = "" />
    <bean id = "defaultFileNoRBACService" class = "" />

    <bean id = "localDatabaseFileService" class = "">
            <constructor-arg ref = "defaultFileDownloadUrlService" />
            <constructor-arg ref = "defaultFileNoRBACService" />
            <property name = "default" value = "true" />

Other implementations

The BlobStore plugin offers another implementation of IFileStorageService, allowing files to be stored on the fileSystem, on a dedicated database or on a remote storage service.

Examples of use

Save an uploaded file :

MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        FileItem fileItem = multipartRequest.getFile (PARAMETER_PROJECT_FILE);

        if (fileItem! = null)
                IFileStoreServiceProvider fileStoreService = FileService.getInstance () .getFileStoreServiceProvider ();

                String strFileStoreKey = fileStoreService.storeFileItem (fileItem);
                _project.setFileKey (strFileStoreKey);

Generation of the download link for the template:

IFileStoreServiceProvider fileStoreService = FileService.getInstance () .getFileStoreServiceProvider ();
String strFileUrl = fileStoreService.getFileDownloadUrlBO (_project.getFileKey ());

model.put ("project_file_url", strFileUrl);

Example of encoded link:

http: // localhost: 8080 / example / jsp / admin / file / download provider = defaultDatabaseFileStoreProvider & data = == O3lmKxHlAX67WE7_WNuLw2Bi0LDlxi2RldReG03f3nyfxcxRzCtGWvU8e08VNiO35C0GGixxKRlQTO5ObMB8ZQ1sLFOEDyKXCEUZL4PR7ClBAcnruis2EyjLdPgPIbtbzwBUj37Vm4RFdVYEbVEbDCFLUMZX6Pufv28q5Ce0JCFjk4NKuot7c3j1FNegx4zXjGE18oIxgDoHxFHXt1VAFmeIP7PKJIU2ZEDLZUw2DluhW-diO9DNF2sN0BmHhn6XiNaBQQ_Ia4Zt5MaB9KpZXL8LxYSzvq8bse2Hxi6SXZtpFF0tzSQ5dBjmLsHSzmn691Li0DsEbLnTB84icM6OlA?