Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Getting image from Blob to front end.  RSS feed

 
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
 
Bartender
Posts: 11445
18
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
Bartender
Posts: 11445
18
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?
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!