Search code examples
javaspringliferayliferay-theme

Uploading images to liferay theme from a portlet


I have Liferay Spring Maven portlet, and a liferay theme. Now user will upload an image through the portlet. How can we place this in /webapps/theme/images? Any inbuilt liferay feature/API which would help us place the uploaded image into the theme?


Solution

  • For file upload functionality, you can refer: How to upload file in relative directory

    For dynamic path of theme's image folder, you can get it through ThemeDisplay object as following:

    Action:

    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);    
    String themeImagePath = themeDisplay.getPortalURL() + themeDisplay.getPathImage();
    

    Where request can be renderRequest or actionRequest.

    JSP:

    <liferay-theme:defineObjects />
    
    String themeImagePath = themeDisplay.getPortalURL() + themeDisplay.getPathImage();
    

    Other relatively used options are themeDisplay().getPathThemeCss(), themeDisplay().getPathJavaScript() or themeDisplay().getPathMain();