330xi
330xi

Reputation: 97

Display image from some server directory

I save uploaded image files in tomcat or portlet temporary directory, and I want to display them. I know their path in server file system, but how generate a right path for displaying it on portlet's page? It must become from smth like:

opt/liferay/tomcat-7.0.27/temp/28-Image-portlet/WEB-INF/classes/intech/webpro/kegor/image/Clipboard02.jpg

to

http://test.com/web/guest/liferay-benefits?p_p_id=Image_WAR_Imageportlet&p_p_lifecycle=2&p_p_state=normal&p_p_mode=view&p_p_cacheability=cacheLevelPage&p_p_col_id=column-1&p_p_col_count=1&_Imag

How to get it?

I know how it is done from portlets resources folder:

#{resource['images:smiley.jpg']}

But how to display image from some server directory in portlet?

Upvotes: 0

Views: 1022

Answers (2)

Ivan.Rigovsky
Ivan.Rigovsky

Reputation: 1

If you only need to display content (without permission check), you can use Tomcat. Put file into /webapps/portlet-name/html/ (or temp/portlet-name/html/) directory. As a result: http://site.com/portlet-name/html/image.jpg

Upvotes: 0

Avinash Singh
Avinash Singh

Reputation: 3777

You can't access images from another server using #{resource['image']} , You can either

1) give the full image path in xhtml

2) Keep the image paths in CSSfile and use CSS classes in xhtml.

3) create a common util function or ResourceHelper ApplicationScoped Bean that has something like
getResource(String imageName) which returns the correct URL. You
can then use it in your xhtml as
#{ResourceHelper.getResource('image.png')}

Upvotes: 0

Related Questions