Class LocalFileMediaStorageStrategy

java.lang.Object
de.hybris.platform.media.storage.impl.LocalFileMediaStorageStrategy
All Implemented Interfaces:
LocalStoringStrategy, MediaStorageStrategy

public class LocalFileMediaStorageStrategy extends Object implements MediaStorageStrategy, LocalStoringStrategy

Strategy which allows to store binaries for Media objects locally in data directory of current platform installation. This strategy supports flat as well as hierarchical way of file storing.

Corresponding MediaFolder have to be configured with following properties:

 media.folder.{mediaFolderQualifier}.storage.strategy=localFileMediaStorageStrategy
 media.folder.{mediaFolderQualifier}.hashing.depth=depth
 

where mediaFolderQualifier is qualifier of MediaFolder and depth is possible depth for subfolder structure. Below is full example for MediaFolder with qualifier foo and depth 2:

 media.folder.foo.storage.strategy=localFileMediaStorageStrategy
 media.folder.foo.hashing.depth=2
 

Strategy can be also configured globally as follows:

 media.default.storage.strategy=localFileMediaStorageStrategy
 media.default.hashing.depth=2
 

To control clean on init behavior use following property:

 media.globalSettings.localFileMediaStorageStrategy.cleanOnInit = true / false
 
Spring Bean ID:
localFileMediaStorageStrategy
  • Field Details

  • Constructor Details

    • LocalFileMediaStorageStrategy

      public LocalFileMediaStorageStrategy()
  • Method Details

    • 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
    • verifyFolderAndLocationIntegrity

      protected void verifyFolderAndLocationIntegrity(MediaStorageConfigService.MediaFolderConfig config, String location)
    • isFolderVerificationDisabled

      protected boolean isFolderVerificationDisabled()
    • 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
    • setStorageConfigService

      public void setStorageConfigService(MediaStorageConfigService storageConfigService)
    • setMainDataDir

      public void setMainDataDir(File mainDataDir)
    • setReplicationDirs

      public void setReplicationDirs(List<File> replicationDirs)
    • setLocationHashService

      public void setLocationHashService(MediaLocationHashService locationHashService)
    • setMimeService

      public void setMimeService(MimeService mimeService)
    • setMediaService

      public void setMediaService(MediaService mediaService)