Interface MediaStorageStrategy

All Known Implementing Classes:
GridFSMediaStorageStrategy, LocalFileMediaStorageStrategy, S3MediaStorageStrategy, WindowsAzureBlobStorageStrategy

public interface MediaStorageStrategy
Strategy for manipulating media binary data. Each binary data connected to Media object is stored in media storage which could be any storage like for instance file system, disk share, FTP. Binary data is identified by its unique location string identifier. After storing binary data by using store(de.hybris.platform.media.storage.MediaStorageConfigService.MediaFolderConfig, java.lang.String, java.util.Map, java.io.InputStream) StoreMediaData object is returned which contains all required informations: unique location string identifier, size and hash for location. All other operations like: delete, get can be performed by using unique location string identifier.
  • Method Details

    • store

      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.
      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
      Throws:
      MediaStoreException - when media stream cannot be stored in storage
    • delete

      void delete(MediaStorageConfigService.MediaFolderConfig config, String location)
      Delete media represented by location from the storage.
      Parameters:
      config - media folder configuration
      location - the string representation of location of media data in storage
      Throws:
      MediaRemovalException - if delete operation in the storage has failed
    • getAsStream

      Gets the media data from the storage as stream.
      Parameters:
      config - media folder configuration
      location - the string representation of location of media data in storage
      Returns:
      the data
      Throws:
      MediaNotFoundException - when media does not exist in the storage
    • getAsFile

      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.
      Parameters:
      config - media folder configuration
      location - the string representation of location of media data in storage
      Returns:
      the media as file
      Throws:
      UnsupportedOperationException - when particular implementation does not support returning data as File
    • getSize

      long getSize(MediaStorageConfigService.MediaFolderConfig config, String location)
      Gets size of media data in bytes.
      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
      Throws:
      MediaNotFoundException - when media does not exist in the storage
    • hasValidMediaFolderName

      default boolean hasValidMediaFolderName(MediaStorageConfigService.MediaFolderConfig config)
      Returns true by default for all storage strategies. If storage strategy requires special media folder naming convention (eg. for evaluating container name) then overrides this method and returns true if media folder name complies with strategy's requirements.
      Parameters:
      config - media folder configuration for retrieving media folder qualifier (media folder name)
      Returns:
      false otherwise