• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting image from Blob to front end.

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm using iBatis as my database connector. not sure if it can return a stream instead. any ideas?
reply
    Bookmark Topic Watch Topic
  • New Topic