You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-user@portals.apache.org by Gia Hieu Dinh <gi...@yahoo.com> on 2007/06/06 19:28:31 UTC

Problem with display binary image in portlet

Hi everyone,
I'm writing a simple portlet to display an image from a binary image.
However, what I get from the portlet is all binary data. This is what I have
done:

		response.setContentType("image/gif");
		OutputStream outStream = response.getPortletOutputStream();
		byte image[] = null;
		try {
			image = getImage();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		outStream.write(image);
		outStream.flush();

and this is my portlet.xml
	<portlet>
		<portlet-name>Image</portlet-name>
		<display-name>Image Portlet</display-name>
		<portlet-class>
			org.apache.ws.axis2.ImageGetter
		</portlet-class>
		<supports>
            <mime-type>text/html</mime-type>
            <portlet-mode>VIEW</portlet-mode>
        </supports>
		<supports>
			<mime-type>image/gif</mime-type>
			<portlet-mode>VIEW</portlet-mode>
		</supports>
		<portlet-info>
			<title>Image Title</title>
		</portlet-info>
	</portlet>

Could anyone please help me out of this.
Thank you so much.
-- 
View this message in context: http://www.nabble.com/Problem-with-display-binary-image-in-portlet-tf3879263.html#a10993320
Sent from the Pluto - User mailing list archive at Nabble.com.


Re: Problem with display binary image in portlet

Posted by be...@netsos.com.
Hi,

Unfortunately, what you are trying to do will not work. 
PortletResponse.setContentType() is really for setting the type of markup
that you are returning.  Typically, you would use "text/html" (just as
with servlets).  However, depending on your portal, you may wish to use
WML, etc.  In JSR 168 there is no way to directly set the HTTP response
headers using the portlet API (since portlets are page fragments, it is
not guaranteed that the container has not already committed content to the
client).  If I am not mistaken, this is what resource serving is all about
in JSR 286.  Anyhow, if you can't wait until then, trying moving the code
that you have below into servlet, and in the markup generated by your
portlet add an <img> tag that points the servlet.

Hope this helps,

Ben

>
> Hi everyone,
> I'm writing a simple portlet to display an image from a binary image.
> However, what I get from the portlet is all binary data. This is what I
> have
> done:
>
> 		response.setContentType("image/gif");
> 		OutputStream outStream = response.getPortletOutputStream();
> 		byte image[] = null;
> 		try {
> 			image = getImage();
> 		} catch (Exception e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
> 		outStream.write(image);
> 		outStream.flush();
>
> and this is my portlet.xml
> 	<portlet>
> 		<portlet-name>Image</portlet-name>
> 		<display-name>Image Portlet</display-name>
> 		<portlet-class>
> 			org.apache.ws.axis2.ImageGetter
> 		</portlet-class>
> 		<supports>
>             <mime-type>text/html</mime-type>
>             <portlet-mode>VIEW</portlet-mode>
>         </supports>
> 		<supports>
> 			<mime-type>image/gif</mime-type>
> 			<portlet-mode>VIEW</portlet-mode>
> 		</supports>
> 		<portlet-info>
> 			<title>Image Title</title>
> 		</portlet-info>
> 	</portlet>
>
> Could anyone please help me out of this.
> Thank you so much.
> --
> View this message in context:
> http://www.nabble.com/Problem-with-display-binary-image-in-portlet-tf3879263.html#a10993320
> Sent from the Pluto - User mailing list archive at Nabble.com.
>
>