This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 60804
    
  65

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: 60804
    
  65

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: 60804
    
  65

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.
 
Similar Threads
how to convert byte[] to blob
Oracle function using Java to return Blob is zero size
BLOB
inserting BLOBs into MySQL database
Inserting BLOB's in database