Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Seeya S Kudtarker
Upload and Display images inLIferay
March 15, 2013 11:23 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

I followed the following thread for uploading images in liferay:

http://www.liferay.com/community/forums/-/message_boards/message/21612680

I am getting an error saying that setContent function is unimplemented. How should I implement setContent in DisplayImageImpl ?
Hitoshi Ozawa
RE: Upload and Display images inLIferay
March 15, 2013 11:49 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7954

Join Date: March 23, 2010

Recent Posts

Can't find "DisplayImageImpl" mentioned in the thread you've referred to.
Seeya S Kudtarker
RE: Upload and Display images inLIferay
March 15, 2013 11:54 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Hitoshi Ozawa:
Iam really sorry. It is the Impl class which I was using in my project which I was trying. I apologise for it. I typed my post while referring to my project.

Ok here is what I have tried using the link I mentioned in my previous reply.

This is my Action Class which I have impllemented under the package : com.test.display.images

package com.test.display.images;

import javax.portlet.ActionRequest;

import javax.portlet.ActionResponse;

import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.Base64;
import com.liferay.portal.kernel.util.File;
import com.liferay.portal.kernel.util.FileUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
import com.test.display.images.model.DisplayImage;
import com.test.display.images.model.impl.DisplayImageImpl;
import com.test.display.images.service.DisplayImageLocalServiceUtil;


/**
* Portlet implementation class displayImage
*/
public class displayImage extends MVCPortlet {

public void uploadImage(ActionRequest arq,ActionResponse ars) throws Exception {
UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(arq);
DisplayImage fileUp = new DisplayImageImpl();
fileUp.setEmpId(CounterLocalServiceUtil.increment("FileUploader.class"));
java.io.File file = uploadRequest.getFile("file");
byte[] bytes = FileUtil.getBytes(file);
fileUp.setContent(Base64.objectToString(bytes));
DisplayImageLocalServiceUtil.addDisplayImage(fileUp);
}

}


And in this function I get error at line : fileUp.setContent(Base64.objectToString(bytes));
The error is :
The method setContent(String) is undefined for the type DisplayImage

How should I implement this method since it is not defined in DisplayImage
Seeya S Kudtarker
RE: Upload and Display images inLIferay
March 16, 2013 12:04 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

And I used: http://vforliferay.blogspot.com/2010/12/fileupload-using-servicexml-file.html
link which is mentioned in the link I have mentioned in my first reply
Seeya S Kudtarker
RE: Upload and Display images inLIferay
March 17, 2013 10:46 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Can anyone help me with this problem?
Seeya S Kudtarker
RE: Upload and Display images inLIferay
March 19, 2013 2:27 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

I finalyy got this working.
I referred http://vforliferay.blogspot.in/2010/12/fileupload-using-servicexml-file.html (I got this link mentioned in one of the forums here in liferay)
Followed the steps making few changes.

But the type for image(which I am storing) remains longtext even after modifying 'portlet-model-hints.xml.
And when I try to display the image I get the long text field.

Anyone can provide any more suggestions on how I should display the images stored in the database?
chirag @ India
RE: Upload and Display images inLIferay
June 11, 2013 11:12 PM
Answer

chirag @ India

Rank: Regular Member

Posts: 129

Join Date: December 20, 2011

Recent Posts

hi Seeya S Kudtarker ,

I referred http://vforliferay.blogspot.in/2010/12/fileupload-using-servicexml-file.html & image store in db as longtext .

I have face same problem how I should display the images stored in the database?

have you solved it ? then share with me.

Thanks
Chirag @ India
Seeya S Kudtarker
RE: Upload and Display images inLIferay
June 17, 2013 9:07 PM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Hi chirag @ India:

Like I said in my previous post, when I tried displaying the image in my jsp, I was getting a long textfield. After folloing the tutorial also.
So what I did was I used Document Library provided by which is better. Also I had time constraints so I used DL Library.
Hav eyou used DL Library?
chirag @ India
RE: Upload and Display images inLIferay
June 17, 2013 9:49 PM
Answer

chirag @ India

Rank: Regular Member

Posts: 129

Join Date: December 20, 2011

Recent Posts

Hi Seeya S Kudtarker ,

Yes I used DL Library,but i want to display from db.so whatever i did last share with you .

 1<%
 2FileUploader s=FileUploaderLocalServiceUtil.getFileUploader(101); // suppose101 fix id
 3             byte[] bytes=s.getContent().getBytes();
 4         
 5            
 6%>
 7<img src="data:image/jpg;base64,<%=bytes%>" />
 8
 9also set mine-type in portlet.xml file
10
11    <supports>
12            <mime-type>image/jpg</mime-type>
13    </supports>


I got crash image in browser .Any ides to display proper image.


Thanks
Chirag
Seeya S Kudtarker
RE: Upload and Display images inLIferay
June 19, 2013 1:44 AM
Answer

Seeya S Kudtarker

Rank: Regular Member

Posts: 187

Join Date: January 15, 2013

Recent Posts

Hi Chirag,
I am sorry I havent tried your approach. But lets hope someone answers this.
If you get a soluiton don't forget to share it here. I would like to know the solution too.
Like I said, due to time constraints I used DL. But I will see if I can find solution