Class FileSystemFileServiceProvider
- All Implemented Interfaces:
FileServiceProvider
This Provider can only be used in production systems that run on a single server or those that have a shared filesystem mounted to the application servers.
- Author:
- bpolster
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String
protected BroadleafFileServiceExtensionManager
protected String
protected int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addOrUpdateResources
(FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) Deprecated.addOrUpdateResourcesForPaths
(FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) Adds all of the given files and returns the resource names of all of them suitable for invokingFileServiceProvider.getResource(String)
and/orFileServiceProvider.removeResource(String)
protected String
buildResourceName
(String url) Stores the file on the file-system by performing an MD5 hash of the the passed in fileNameprotected String
getBaseDirectory
(boolean skipSite) Returns a base directory (unique for each tenant in a multi-tenant installation.getResource
(String url) Returns a File representing the passed in url.getResource
(String url, FileApplicationType applicationType) Returns a File representing the passed in name and application type.protected String
getSiteDirectory
(String baseDirectory) Creates a unique directory on the file system for each site.boolean
removeResource
(String name) Removes the resource from the file service.
-
Field Details
-
fileSystemBaseDirectory
-
maxGeneratedDirectoryDepth
@Value("${asset.server.max.generated.file.system.directories}") protected int maxGeneratedDirectoryDepth -
extensionManager
-
baseDirectory
-
-
Constructor Details
-
FileSystemFileServiceProvider
public FileSystemFileServiceProvider()
-
-
Method Details
-
getResource
Description copied from interface:FileServiceProvider
Returns a File representing the passed in url. All separators in the given url should be in URL-separator form meaning '/' rather than '\' (like on Windows).- Specified by:
getResource
in interfaceFileServiceProvider
- Parameters:
url
- - fully qualified path to the resource- Returns:
-
getResource
Description copied from interface:FileServiceProvider
Returns a File representing the passed in name and application type. Providers may choose to cache certain FileApplicationType(s) locally rather than retrieve them from a remote source.- Specified by:
getResource
in interfaceFileServiceProvider
- Parameters:
url
- - the URL-representation of the resource. This means that paths should always have / separators rather than system-specific valuesapplicationType
- applicationType- Returns:
- a File to the
-
addOrUpdateResources
@Deprecated public void addOrUpdateResources(FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) Deprecated.Description copied from interface:FileServiceProvider
Takes in a work area and application type and moves all of the files to the configured FileProvider.- Specified by:
addOrUpdateResources
in interfaceFileServiceProvider
files
- the files that should be copied
-
addOrUpdateResourcesForPaths
public List<String> addOrUpdateResourcesForPaths(FileWorkArea workArea, List<File> files, boolean removeFilesFromWorkArea) Description copied from interface:FileServiceProvider
Adds all of the given files and returns the resource names of all of them suitable for invokingFileServiceProvider.getResource(String)
and/orFileServiceProvider.removeResource(String)
- Specified by:
addOrUpdateResourcesForPaths
in interfaceFileServiceProvider
- Returns:
- the resource names for each file that was uploaded. The resource names that are returned should be for each file in file
-
removeResource
Description copied from interface:FileServiceProvider
Removes the resource from the file service.- Specified by:
removeResource
in interfaceFileServiceProvider
- Parameters:
name
- - fully qualified path to the resource- Returns:
- true if the resource was removed
-
buildResourceName
Stores the file on the file-system by performing an MD5 hash of the the passed in fileNameTo ensure that files can be stored and accessed in an efficient manner, the system creates directories based on the characters in the hash.
For example, if the URL is /product/myproductimage.jpg, then the MD5 would be 35ec52a8dbd8cf3e2c650495001fe55f resulting in the following file on the filesystem {assetFileSystemPath}/35/ec/myproductimage.jpg.
The hash for the filename will include a beginning slash before performing the MD5. This is done largely for backward compatibility with similar functionality in BLC 3.0.0.
This algorithm has the following benefits: - Efficient file-system storage with - Balanced tree of files that supports 10 million files
If support for more files is needed, implementors should consider one of the following approaches: 1. Overriding the maxGeneratedFileSystemDirectories property from its default of 2 to 3 2. Overriding this method to introduce an alternate approach
- Parameters:
url
- The URL used to represent an asset for which a name on the fileSystem is desired.- Returns:
-
getBaseDirectory
Returns a base directory (unique for each tenant in a multi-tenant installation. Creates the directory if it does not already exist. -
getSiteDirectory
Creates a unique directory on the file system for each site. Each site may be in one of 255 base directories. This model efficiently supports up to 65,000 sites served from a single file system based on most OS systems ability to quickly access files as long as there are not more than 255 directories.- Parameters:
baseDirectory
- The starting directory for local files which must end with a '/';
-