Search code examples
configurationpersistenceliferayportleteditmode

How to store uploaded images via portlet preference view in Liferay


I'm gonna develope banner rotator porlet in Liferay, that will have preference view (Configuration view), from where admin could manage banner rotate images, uploading them from computer and setting its title and description.

My question is, where should I store uploaded images and its informations? My banner-rotator portlet initially will be empty. I want images be related to liferay portal, not portlet itself. Is there predefined liferay documented way I should follow?

With short words, I need to store images, images title, images description

I use liferay 6.0.5


Solution

  • I think that you should create structure and template that will represent your banner.

    Your admin would create article, for each banner, with that structure/template. Your portlet would search for articles based on your structure/template, or you could use some category ("banner"?) or use custom article type for searching.

    Or even simpler way would be that your admin should upload banners in specific folder of "Image gallery" and your portlet has configuration only for entering folder id. Portlet would simply iterate over that folder and use data from returned IGImage objects.

    UPDATE:

    If you must upload images from portlet preferences than create from with required fields. Using that data and uploaded image use liferay's api to store it in image gallery.

    See

    com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil.addImage(long, long, long, String, String, File, String, ServiceContext);
    com.liferay.portlet.imagegallery.service.IGImageLocalServiceUtil.addIGImage(IGImage);
    com.liferay.portlet.imagegallery.model.IGImage
    

    IGImage instance has lot of properties among which are fields that you want.