Foros de discusión

display image from database (blob) mysql

thumbnail
akash rathod, modificado hace 12 años.

display image from database (blob) mysql

New Member Mensajes: 22 Fecha de incorporación: 6/10/11 Mensajes recientes
hi..friends

i have stored the image in table in blob format..

while showing this image on portlet ..there are some error..
like java.lang.IllegalStateException: Cannot obtain OutputStream because Writer is already in use

my code is in jsp

                      <%          String sql1= "SELECT userId,comments,createDate,imageup from wallpost where groupId='"+ groupid +"'order by createDate desc ";
					     rs1 = stmt.executeQuery(sql1);
                            while (rs1.next()) {

                                     try
				   		   {
				   		 out.clearBuffer();
				   		   image = rs1.getBlob(1);
					        imgData = image.getBytes(1,(int) image.length());
					       
					        response.setContentType("image/gif");
					        OutputStream o = response.getOutputStream();
					        o.write(imgData);
					        o.flush();
					        o.close();
					        
				   		   }catch(Exception eb){
				   			   System.out.println("show image"+eb);
				   		   }
                                       }
                      %>
thumbnail
David H Nebinger, modificado hace 12 años.

RE: display image from database (blob) mysql

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
Right, because your jsp is called as part of a whole page that Liferay is currently building and you cannot just start spitting out image data into the stream.

Your portlet page is going to have to include in the URL the right path to get to the jsp page within your portlet (servlet).
thumbnail
akash rathod, modificado hace 12 años.

RE: display image from database (blob) mysql

New Member Mensajes: 22 Fecha de incorporación: 6/10/11 Mensajes recientes
hi David sir..
Can you plz tell me any alternative way to display the same image on portlet.
thumbnail
David H Nebinger, modificado hace 12 años.

RE: display image from database (blob) mysql

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
For this you would probably need a dedicated servlet w/ an image link in the generated view that uses the servlet call to pull the image from the database and return it to the browser using appropriate header values.

Is there some reason you haven't considered using the image library? All of this would be taken care of you...
Muhd Heikel, modificado hace 11 años.

RE: display image from database (blob) mysql

New Member Mensaje: 1 Fecha de incorporación: 24/05/12 Mensajes recientes
Hi,

I'm a beginner in Liferay and right now I also faced a similar problem to display image in portlet and my coding is similar with the first one.
The error occured during this line:

OutputStream o= response.getOutputStream();

Really hope someone can show me how to solve this error

Thank you.
thumbnail
David H Nebinger, modificado hace 11 años.

RE: display image from database (blob) mysql

Liferay Legend Mensajes: 14919 Fecha de incorporación: 2/09/06 Mensajes recientes
The error is your code. That is what needs to be fixed. We discussed why it cannot be implemented in the way the OP did it. The same discussion would apply to your code.
thumbnail
Hitoshi Ozawa, modificado hace 12 años.

RE: display image from database (blob) mysql

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Seems you're having a problem similar to the problem mentioned in the following LPS. Check the comment section for a contributed solution:

http://issues.liferay.com/browse/LPS-13720