Search code examples
sap-commerce-cloud

Hybris prettyURL showing PK instead of the real file name


The file-name of any image is appearing like /de-de/medias/sys_master/images/images/h9c/h5f/8796178743326/8796178743326.jpg in the url. Instead of 8796178743326.jpg there should be file-name.jpg I have already set media.legacy.prettyURL=true 8796178743326 is the PK of the image. Any help!


Solution

  • With the prettyURL, if there is no realfilename value in media instance then URL will end with PK instead real file name.

    /medias/sys_master/images/images/h9c/h5f/8796178743326/8796178743326.jpg
    

    If you really want the file name in the URL then you have to edit respective media from the backoffice/impex and assign value to the realFileName attribute.

    Have a look into assembleLegacyURL method of LocalMediaWebURLStrategy class

            String realFileName = this.getRealFileNameForMedia(mediaSource);
    
            if (realFileName == null) {
    
                  basePath = mediaSource.getLocation().substring(0, lastDotIdx);
                  lastDotIndexForRealFileName = StringUtils.lastIndexOf(basePath, '/');
                  String fileName = basePath.substring(lastDotIndexForRealFileName + 1);
    
                  sb.append(basePath).append("/").append(fileName).append('.').append(fileExtension);
    
    
               } else {
                  basePath = location.substring(0, lastDotIdx);
                  lastDotIndexForRealFileName = realFileName.lastIndexOf(46);
                  if (lastDotIndexForRealFileName != -1) {
    
                     realFileName = realFileName.substring(0, lastDotIndexForRealFileName);
                  }
                  sb.append(basePath).append("/").append(realFileName).append('.').append(fileExtension);
               }