Class GridFSMediaStorageStrategy

java.lang.Object
de.hybris.platform.gridfs.media.storage.GridFSMediaStorageStrategy
All Implemented Interfaces:
MediaStorageStrategy

public class GridFSMediaStorageStrategy extends Object implements 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 Details

    • tenantPrefix

      protected String 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: MediaStorageStrategy
      Stores 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 a mediaId as unique part. mediaId is generated by platform for each upload attempt so it guarantees uniqueness.
      Specified by:
      store in interface MediaStorageStrategy
      Parameters:
      config - media folder configuration
      mediaId - the media identifier
      metaData - the meta data containing additional possible informations like: original filename, MIME, folder path
      dataStream - the data stream to store
      Returns:
      object containing information about stored data like unique location in the storage, size and hash for location
    • delete

      public void delete(MediaStorageConfigService.MediaFolderConfig config, String location)
      Description copied from interface: MediaStorageStrategy
      Delete media represented by location from the storage.
      Specified by:
      delete in interface MediaStorageStrategy
      Parameters:
      config - media folder configuration
      location - the string representation of location of media data in storage
    • getAsStream

      public InputStream getAsStream(MediaStorageConfigService.MediaFolderConfig config, String location)
      Description copied from interface: MediaStorageStrategy
      Gets the media data from the storage as stream.
      Specified by:
      getAsStream in interface MediaStorageStrategy
      Parameters:
      config - media folder configuration
      location - 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

      public File getAsFile(MediaStorageConfigService.MediaFolderConfig config, String location)
      Description copied from interface: MediaStorageStrategy
      Gets 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:
      getAsFile in interface MediaStorageStrategy
      Parameters:
      config - media folder configuration
      location - the string representation of location of media data in storage
      Returns:
      the media as file
    • getSize

      public long getSize(MediaStorageConfigService.MediaFolderConfig config, String location)
      Description copied from interface: MediaStorageStrategy
      Gets size of media data in bytes.
      Specified by:
      getSize in interface MediaStorageStrategy
      Parameters:
      config - media folder configuration
      location - the string representation of location of media data in storage
      Returns:
      the size of an media data in bytes