Search code examples
sap-commerce-cloud

How to get an existing MediaContainerModel in hybris?


I tried to get MediaFormatModel, MediaModel, MediaFolderModel etc with the help of MediaService but only the MediaContainer is not possible to get from MediaService and I tried with ModelService. Only one possibility I found that by getting MediaModel we can get the MediaContainerModel but I need to get specific MediaContainerModel by passing qualifier. Like for example:

final MediaModel mm1 = mediaService.getMedia(catalogVersion, "picture515x515");
final MediaFormatModel mf1200 = mediaService.getFormat("1200x1200");
final MediaFolderModel mfm = mediaService.getFolder("convertedimages");

any help?


Solution

  • I got the solution we can get as follows

    @Autowired
    MediaContainerService mediaContainerService;

    ......
    MediaContainerModel mediaContainer = null;
    try
    {
    mediaContainer =
    mediaContainerService.getMediaContainerForQualifier("testContainer"); }
    catch (final Exception e)
    {
    mediaContainer = createMediaContainer("testContainer");
    }
    mediaContainer.setCatalogVersion(catalogVersion);