Class GridFSMediaStorageStrategy

  • All Implemented Interfaces:
    MediaStorageStrategy

    public class GridFSMediaStorageStrategy
    extends java.lang.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 Detail

      • tenantPrefix

        protected java.lang.String tenantPrefix
    • Constructor Detail

      • GridFSMediaStorageStrategy

        public GridFSMediaStorageStrategy​(org.springframework.data.mongodb.MongoDbFactory dbFactory,
                                          MediaLocationHashService mediaLocationHashService)
    • Method Detail

      • setTenantPrefix

        public void setTenantPrefix()
      • store

        public StoredMediaData store​(MediaStorageConfigService.MediaFolderConfig config,
                                     java.lang.String mediaId,
                                     java.util.Map<java.lang.String,​java.lang.Object> metaData,
                                     java.io.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
      • buildGridFsInstance

        protected com.mongodb.gridfs.GridFS buildGridFsInstance​(java.lang.String bucketName)
      • getAsFile

        public java.io.File getAsFile​(MediaStorageConfigService.MediaFolderConfig config,
                                      java.lang.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