FileService
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 = "fr.paris.lutece.portal.service.file.implementation.DefaultFileDownloadService" /> <bean id = "defaultFileNoRBACService" class = "fr.paris.lutece.portal.service.file.implementation.DefaultFileNoRBACService" /> <bean id = "localDatabaseFileService" class = "fr.paris.lutece.portal.service.file.implementation.LocalDatabaseFileService"> <constructor-arg ref = "defaultFileDownloadUrlService" /> <constructor-arg ref = "defaultFileNoRBACService" /> <property name = "default" value = "true" /> </bean>
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 :
// get default file service provider IFileStoreServiceProvider fileStoreService = FileService.getInstance( ).getFileStoreServiceProvider( ); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; FileItem fileItem = multipartRequest.getFile( PARAMETER_PROJECT_FILE ); if ( fileItem != null ) { try { String strFileStoreKey = fileStoreService.storeFileItem( fileItem ); _project.setFileKey( strFileStoreKey ); } catch ( FileServiceException e ) { (...)
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?