Downloading image

305 views
Skip to first unread message

hou0175

unread,
Oct 23, 2009, 9:52:02 PM10/23/09
to Google Web Toolkit
Hello experts,

I'm trying to create a page where I can display images stored in a
database.

I've writen the server code as follows.

public void doGet(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException
{
//the code to retrieve the image from database ...

response.reset();
response.setContentType("image/jpg");

ServletOutputStream os = response.getOutputStream();
Blob imageBlob = imageItem.GetImageBlob();
byte [] imageData = imageBlob.getBytes();
os.write(imageData);
}

I'm calling 'doGet' via RequestBuilder, but I haven't found a way to
get the image on my client side and display it on an GWT Image object.

Am I using the wrong approach here?

I'd appreciate if anyone could send me some sample code showing how to
get the response on the client side and displaying the image on an
Image object.

Thank you

Dalla

unread,
Oct 24, 2009, 3:40:32 AM10/24/09
to Google Web Toolkit
Wouldn´t you need to flush/close the stream aswell?

Thomas Broyer

unread,
Oct 24, 2009, 6:26:27 AM10/24/09
to Google Web Toolkit


On 24 oct, 03:52, hou0175 <kajita...@gmail.com> wrote:
> Hello experts,
>
> I'm trying to create a page where I can display images stored in a
> database.
>
> I've writen the server code as follows.
>
> public void doGet(HttpServletRequest request, HttpServletResponse
> response)
>                                         throws ServletException, IOException
> {
>          //the code to retrieve the image from database ...
>
>         response.reset();
>         response.setContentType("image/jpg");
>
>         ServletOutputStream  os = response.getOutputStream();
>         Blob imageBlob = imageItem.GetImageBlob();
>         byte [] imageData = imageBlob.getBytes();
>         os.write(imageData);
>
> }
>
> I'm calling 'doGet' via RequestBuilder, but I haven't found a way to
> get the image on my client side and display it on an GWT Image object.
>
> Am I using the wrong approach here?

Yes, just use new Image(GWT.getHostPageBaseURL() +
"myImageServingServlet") instead.

Reply all
Reply to author
Forward
0 new messages