This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retrieving a blob object for download.

 
Vincent Oh
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My file is saved as a Blob object in mySQL database in the form of byte[]. How should i convert it in my servlet to send it back in the HttpServletResponse?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Convert it to what?
 
Vincent Oh
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Convert it to something then i can return to the client side for download. Do i have to convert it to a File before writing it as a stream to the Response?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you can just stream the data. Depending upon what the "file" is supposed to be -- apparently it's a big secret -- you need to set the response headers appropriately.
 
Vincent Oh
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:No, you can just stream the data. Depending upon what the "file" is supposed to be -- apparently it's a big secret -- you need to set the response headers appropriately.


the file could be in any format like jpg, doc, csv, xls, etc etc. it's like an attachment function. how do you code the streaming from byte[] to the response? i always got problem with streams X_x
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64182
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Search this forum for previous discussion -- this has been discussed many times. There are also likely to be may examples out there elsewhere.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic