Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting image from Blob to front end.

 
Vincent Oh
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Vincent Oh
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm using iBatis as my database connector. not sure if it can return a stream instead. any ideas?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic