Class GridFSMediaStorageStrategy
java.lang.Object
de.hybris.platform.gridfs.media.storage.GridFSMediaStorageStrategy
- All Implemented Interfaces:
MediaStorageStrategy
Strategy which allows to store binaries for Media objects in MongoDB GridFS data storage.
MongoDB GridFS storage has to be configured with following properties:
media.globalSettings.gridFsStorageStrategy.mongo.host=host media.globalSettings.gridFsStorageStrategy.mongo.port=port media.globalSettings.gridFsStorageStrategy.mongo.dbname=dbname media.globalSettings.gridFsStorageStrategy.username=optional username media.globalSettings.gridFsStorageStrategy.password=optional password
where:
- host is MongoDB server host
- port is MongoDB server port
- dbname is MongoDB database to use as storage
- username is username for user having read/write rigths in database
- password is password for user having read/write rigths in database
Corresponding MediaFolder has to be configured with following properties:
media.folder.{mediaFolderQualifier}.storage.strategy=gridFsStorageStrategy
media.folder.{mediaFolderQualifier}.bucketId=myBucket
where:
- bucketId is name of the bucket
Below is full example for MediaFolder with qualifier mongoFiles and bucketId myBucket:
media.folder.mongoFiles.storage.strategy=gridFsStorageStrategy media.folder.mongoFiles.bucketId=myBucket
If you have more than one media folders, you can share common settings as follows:
media.gridFs.globalSettings.gridFsStorageStrategy.bucketId = myBucket
To control clean on init behavior use following property:
media.gridFs.globalSettings.gridFsStorageStrategy.cleanOnInit = true / false
- Spring Bean ID:
- gridFsStorageStrategy
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGridFSMediaStorageStrategy(MediaLocationHashService mediaLocationHashService, org.springframework.data.mongodb.core.convert.MappingMongoConverter mongoConverter, org.springframework.data.mongodb.MongoDatabaseFactory mongoDatabaseFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoiddelete(MediaStorageConfigService.MediaFolderConfig config, String location) Delete media represented by location from the storage.getAsFile(MediaStorageConfigService.MediaFolderConfig config, String location) Gets the media data from the storage as file.getAsStream(MediaStorageConfigService.MediaFolderConfig config, String location) Gets the media data from the storage as stream.protected org.springframework.data.mongodb.gridfs.GridFsTemplatelonggetSize(MediaStorageConfigService.MediaFolderConfig config, String location) Gets size of media data in bytes.voidstore(MediaStorageConfigService.MediaFolderConfig config, String mediaId, Map<String, Object> metaData, InputStream dataStream) Stores media data into the storage using unique location identifier.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface de.hybris.platform.media.storage.MediaStorageStrategy
hasValidMediaFolderName
-
Field Details
-
tenantPrefix
-
-
Constructor Details
-
GridFSMediaStorageStrategy
public GridFSMediaStorageStrategy(MediaLocationHashService mediaLocationHashService, org.springframework.data.mongodb.core.convert.MappingMongoConverter mongoConverter, org.springframework.data.mongodb.MongoDatabaseFactory mongoDatabaseFactory)
-
-
Method Details
-
setTenantPrefix
public void setTenantPrefix() -
store
public StoredMediaData store(MediaStorageConfigService.MediaFolderConfig config, String mediaId, Map<String, Object> metaData, InputStream dataStream) Description copied from interface:MediaStorageStrategyStores media data into the storage using unique location identifier. Location identifier is computed by each implementation in different way which depends on API of underlying media storage but in most cases contains amediaIdas unique part.mediaIdis generated by platform for each upload attempt so it guarantees uniqueness.- Specified by:
storein interfaceMediaStorageStrategy- Parameters:
config- media folder configurationmediaId- the media identifiermetaData- the meta data containing additional possible informations like: original filename, MIME, folder pathdataStream- the data stream to store- Returns:
- object containing information about stored data like unique location in the storage, size and hash for location
-
delete
Description copied from interface:MediaStorageStrategyDelete media represented by location from the storage.- Specified by:
deletein interfaceMediaStorageStrategy- Parameters:
config- media folder configurationlocation- the string representation of location of media data in storage
-
getAsStream
Description copied from interface:MediaStorageStrategyGets the media data from the storage as stream.- Specified by:
getAsStreamin interfaceMediaStorageStrategy- Parameters:
config- media folder configurationlocation- the string representation of location of media data in storage- Returns:
- the data
-
getGridFsTemplate
protected org.springframework.data.mongodb.gridfs.GridFsTemplate getGridFsTemplate(MediaStorageConfigService.MediaFolderConfig config) -
getAsFile
Description copied from interface:MediaStorageStrategyGets the media data from the storage as file. Note that implementation of this method may be optional when underlying media storage does not support downloading data as File.- Specified by:
getAsFilein interfaceMediaStorageStrategy- Parameters:
config- media folder configurationlocation- the string representation of location of media data in storage- Returns:
- the media as file
-
getSize
Description copied from interface:MediaStorageStrategyGets size of media data in bytes.- Specified by:
getSizein interfaceMediaStorageStrategy- Parameters:
config- media folder configurationlocation- the string representation of location of media data in storage- Returns:
- the size of an media data in bytes
-