wood burning stoves 2.0*
The moose likes Servlets and the fly likes Retrieving a blob object for download. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Retrieving a blob object for download." Watch "Retrieving a blob object for download." New topic
Author

Retrieving a blob object for download.

Vincent Oh
Ranch Hand

Joined: Jan 02, 2012
Posts: 33
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

Convert it to what?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vincent Oh
Ranch Hand

Joined: Jan 02, 2012
Posts: 33
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

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

Joined: Jan 02, 2012
Posts: 33
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

Search this forum for previous discussion -- this has been discussed many times. There are also likely to be may examples out there elsewhere.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Retrieving a blob object for download.