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?
1
votes
I would never change the file in the theme. What if your theme is in a WAR file? What about caching (usually the images form a WAR a cached in the browser)? What about security? You could upload the image into "Documents and Media" instead and include that one in the theme - that would be even easier to implement...
– Tobias Liefke
@Tobian I dropped the idea of uploading the image to theme, since next time when we release new version of the same, the uploaded data will be lost. Instead I will be uploading the image to a directory on the file system and read it from there.
– Seeker
Veeru A S, as upto your question, my answer has satisfied your requirement. You should accept the answer, if it has met your requirement so that it may be trusted as helpful for others as well.
– Parkash Kumar
1 Answers
3
votes
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()
;