Interface StorageProvider
- All Known Implementing Classes:
FilesystemStorageProvider,GoogleCloudStorageProvider
This interface exposes methods required for interacting with a asset storage provider, that is,
to store, retrieve, and delete digital content. In other words, this service is responsible for
supporting internal assets that Broadleaf has access and
responsibility to store. It should be implemented for each type of storage provider to be used.
By default, there should only be a single implementation of this service used, meaning that there
should only be one storage provider used by the Asset service.
Note this service's use is restricted by a MIME type whitelist (see
isWhitelistedMimeType(String)). This means that implementors can restrict what kinds of
files can be supported. This method is linked to a system property of the form
broadleaf.asset.internal.storageProvider.mimeTypeWhitelist.
This service can handle creating new resources from either an InputStream
(addResourceFromStream(InputStream, String), addResourcesFromStreams(Map)) or
by moving files from a temporary workspace (moveResourceFromDirectory(File)
moveResourcesFromDirectory(Iterable)). Also note that, in the case of failures while
processing multiple resources in either the add or
delete methods, the default implementation will try to process
as many resources as possible before returning a composite exception with all files that failed
and their causes (see BulkStorageException).
- Author:
- Nathan Moore (nathanmoore), Samarth Dhruva (samarthd)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionaddResourceFromStream(InputStream resource, String fileName) Adds a new resource to the configured storage provider using the providedInputStreamand filename.addResourcesFromFiles(Map<String, File> fileNamesToResources) addResourcesFromStreams(Map<String, InputStream> fileNamesToResources) Adds new resources to the configured storage provider using the providedMapofInputStreamsand filenames.voiddeleteResource(String path) Deletes the resource in the configured storage provider at the given path string if it exists.voiddeleteResources(Iterable<String> paths) Deletes the resources in the configured storage provider at the given path strings if they exist.booleanisWhitelistedMimeType(String mimeType) Determines whether the given MIME type string is supported by this provider.default StringmoveResourceFromDirectory(File resource) Moves a givenresourcefrom a directory to the configured storage provider and returns the path as a string to the resource within that provider.default PathmoveResourceFromDirectoryAndGetPath(File resource) moveResourcesFromDirectory(Iterable<File> resources) Moves all the givenresourcesfrom a directory to the configured storage provider and returns the paths to the resources within that provider as strings.moveResourcesFromDirectoryAndGetPaths(Iterable<File> resources) readResource(String path) Deprecated, for removal: This API element is subject to removal in a future version.readResources(Iterable<String> paths) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofreadStreamableResources(Iterable)default Optional<org.springframework.core.io.Resource>readStreamableResource(String path) Retrieves theresourcein the configured storage provider at the given path string if it exists.default Iterable<org.springframework.core.io.Resource>readStreamableResources(Iterable<String> paths) Retrieves theresourcesin the configured storage provider at the given path strings if they exist.default Iterable<ResourceWithMetadata>Retrieves theresourcesin the configured storage provider at the given path strings if they exist.Retrieves theresourcein the configured storage provider at the given path string if it exists.
-
Method Details
-
isWhitelistedMimeType
Determines whether the given MIME type string is supported by this provider. Files with MIME types not supported, cannot be stored using this provider. The whitelist can be configured using a system property of the formbroadleaf.asset.internal.storageProvider.mimeTypeWhitelist.If the whitelist is empty, then all types are considered whitelisted.
- Parameters:
mimeType- the mime type to check against the provider's whitelist- Returns:
- whether the given MIME type string is supported by this provider.
- See Also:
-
readResource
@Deprecated(since="2.0.1", forRemoval=true) @NonNull default Optional<File> readResource(@NonNull String path) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofreadStreamableResourceWithMetadata(String)Retrieves theresourcein the configured storage provider at the given path string if it exists. -
readStreamableResource
Retrieves theresourcein the configured storage provider at the given path string if it exists.- Parameters:
path- fully qualified path to the resource's location in the storage provider- Returns:
- Either the
resourcewrapped in anOptionalif it exists or elseOptional.empty().
-
readStreamableResourceWithMetadata
Retrieves theresourcein the configured storage provider at the given path string if it exists.- Parameters:
path- fully qualified path to the resource's location in the storage provider- Returns:
- Either the
resourcewrapped in anOptionalif it exists or elseOptional.empty().
-
readResources
@Deprecated(since="2.0.1", forRemoval=true) @NonNull default Iterable<File> readResources(@NonNull Iterable<String> paths) Deprecated, for removal: This API element is subject to removal in a future version.in favor ofreadStreamableResources(Iterable)Retrieves theresourcesin the configured storage provider at the given path strings if they exist. -
readStreamableResources
default Iterable<org.springframework.core.io.Resource> readStreamableResources(Iterable<String> paths) Retrieves theresourcesin the configured storage provider at the given path strings if they exist.- Parameters:
paths- fully qualified path to the resources' locations in the storage provider- Returns:
Iterableofresourcesthat were found
-
readStreamableResourcesWithMetadata
Retrieves theresourcesin the configured storage provider at the given path strings if they exist. -
addResourceFromStream
Adds a new resource to the configured storage provider using the providedInputStreamand filename. Then, it returns the fully qualified path of the newly stored resource.- Parameters:
resource-resourceto add to the configured storage providerfileName- the name of the resource, potentially including path segments.- Returns:
- the fully qualified path to the added resource
- Throws:
StorageException- if there is an issue processing the resource
-
addResourcesFromStreams
@NonNull BulkAddResourcesResponse addResourcesFromStreams(@NonNull Map<String, InputStream> fileNamesToResources) Adds new resources to the configured storage provider using the provided
MapofInputStreamsand filenames. Then, it returns aBulkAddResourcesResponsecontaining the information about which files succeeded and which files failed.- Parameters:
fileNamesToResources- a map of filenames toresourcesthat should be copied to the storage provider. The filenames can include path segments.- Returns:
- a
BulkAddResourcesResponsecontaining the details of which files did and didn't succeed
-
addResourcesFromFiles
@NonNull BulkAddResourcesResponse addResourcesFromFiles(@NonNull Map<String, File> fileNamesToResources) Adds new resources to the configured storage provider using the providedMapofFilesand filenames. Then, it returns aBulkAddResourcesResponsecontaining the information about which files succeeded and which files failed.- Parameters:
fileNamesToResources- a map of filenames toresourcesthat should be copied to the storage provider. The filenames can include path segments.- Returns:
- a
BulkAddResourcesResponsecontaining the details of which files did and didn't succeed
-
deleteResource
Deletes the resource in the configured storage provider at the given path string if it exists.- Parameters:
path- fully qualified path to the resource's location in the storage provider- Throws:
StorageException- if there was an error in deleting the resource
-
deleteResources
Deletes the resources in the configured storage provider at the given path strings if they exist. This method will attempt to remove all the resources it can successfully before throwing aBulkStorageExceptioncontaining all the failures and their causes.- Parameters:
paths- fully qualified paths to the resources' locations in the storage provider- Throws:
BulkStorageException- if there were errors in deleting some resources
-
moveResourceFromDirectory
Moves a givenresourcefrom a directory to the configured storage provider and returns the path as a string to the resource within that provider.- Parameters:
resource-resourceto move to the configured storage provider- Returns:
- the path to the added file
-
moveResourceFromDirectoryAndGetPath
-
moveResourcesFromDirectory
Moves all the givenresourcesfrom a directory to the configured storage provider and returns the paths to the resources within that provider as strings. -
moveResourcesFromDirectoryAndGetPaths
@NonNull default Iterable<Path> moveResourcesFromDirectoryAndGetPaths(@NonNull Iterable<File> resources)
-
readStreamableResourceWithMetadata(String)