| Author |
Read Blobs
|
Raj Puri
Ranch Hand
Joined: Apr 24, 2003
Posts: 189
|
|
|
I have an Oracle database with tables(BLOBS) populated with pdf or word files and I want to read the table and output it to screen so that user can view in browser. Any code snippet will help. Thanks.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56554
|
|
|
Moved to Servlets.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Raj Puri
Ranch Hand
Joined: Apr 24, 2003
Posts: 189
|
|
|
Any one on this please?
|
 |
D Rog
Ranch Hand
Joined: Feb 07, 2004
Posts: 471
|
|
You should move your question to JDBC forum anyway here is an: Blob b = rs.getBlob(1); int len = (int)b.length(); byte [] _blob = b.getBytes(1, len); Oracle can provide only limited number of bytes in this use, so you won't be able to read multi gig files. If it's your case, then let me know, and I will give you Oracle specific example working with huge files.
|
Get power of your iPod with MediaChest | Minimal J2EE container is here | Light weight full J2EE stack | My blog | Co-author of "Windows programming in Turbo Pascal"
|
 |
Raj Puri
Ranch Hand
Joined: Apr 24, 2003
Posts: 189
|
|
I guess only administrator can move this to JDBC. I have big files typically 1 MB+. Can you post your code in this instance for our learning. Thanks.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56554
|
|
Unless you are having trouble putting the data into the db (which I assume from your original post that you are not) then this is not a JDBC question. From your original question (and the repeat you posted in JSP) I assume that the problem you are having is with streaming the data to the browser? [ May 20, 2005: Message edited by: Bear Bibeault ]
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
|
Are you trying to process the files on the server and render them as HTML or do you just want to stream the files "en masse" down to the browser?
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
Raj Puri
Ranch Hand
Joined: Apr 24, 2003
Posts: 189
|
|
|
I have files stored as word, pdf, xls in database. I do not have problem retriving them into a Blob variable from database. Only question is how to show them in browser. I will expect pdf should open in browser in acrobat, word in word and xls in excel. This is where I have problem. My approach to use in JSP did not work as I believe the setcontenttype failed and it shows like bunch of data. Any idea? I read from posting above I should do servlet but why - After all JSP==Servlet?
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
Yes, streaming binary data from JSPs is ugly at best. Here is an example. It doesn't use blobs. It uses files retrieved with getResourceAsStream but, once you get the blob into an inputStream everything else should be the same. The key line (bold) is the content disposition header. The "inline" keyword tells your browser to open the document as an embedded PDF or Excel sheet. The contentType header tells it what what the file is so it can pick the right application. [ May 20, 2005: Message edited by: Ben Souther ]
|
 |
 |
|
|
subject: Read Blobs
|
|
|