It's not a secret anymore!*
The moose likes GWT and the fly likes Getting image from Blob to front end. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » GWT
Bookmark "Getting image from Blob to front end." Watch "Getting image from Blob to front end." New topic
Author

Getting image from Blob to front end.

Vincent Oh
Ranch Hand

Joined: Jan 02, 2012
Posts: 33
Hi, first of all, I'm not sure if i'm posting at the correct section since my problem cover across a few sections (I think).

Ok so here's the situation:

I have a saved record with a Blob field in the database saved in byte[] using iBatis.
So now I need to retrieve it through the servlet. And because I'm using SmartGWT, i will need to parse the record (in a JavaBean object) to a XML to be sent from the Server to the Client side.

Question:
How do I convert the byte[] into a proper data type so that I can parse it into a XML and send it over so I can display the picture on the client side?
If i decide to use a link which will allow user to click and download the image instead of displaying it directly, how do i do it?

Thanks and regards
Vincent
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10270
    
    8

I would prefer to approach it a bit differently.
The GWT Image class has an overridden constructor which accepts an URL. On the UI, let this point to your servlet.
In the servlet side, it would be the standard procedure of converting the byte[] to an Image and writing it to the stream.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Vincent Oh
Ranch Hand

Joined: Jan 02, 2012
Posts: 33
hmm.. what if i need to do for a download upon clicking on a link?

i'm following this http://www.java-forums.org/blogs/servlet/668-how-write-servlet-sends-file-user-download.html

but how do i send the byte[] from the database to the HttpServletResponse in the servlet?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10270
    
    8

Vincent Oh wrote:
but how do i send the byte[] from the database to the HttpServletResponse in the servlet?

Recommended reading http://stackoverflow.com/questions/2979758/writing-image-to-servlet-response-with-best-performance
Vincent Oh
Ranch Hand

Joined: Jan 02, 2012
Posts: 33
i'm using iBatis as my database connector. not sure if it can return a stream instead. any ideas?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting image from Blob to front end.