• Post Reply Bookmark Topic Watch Topic
  • New Topic

need to convert oracle blob into a file  RSS feed

 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

I need to convert the oracle blob into a file and probably show it on my JSP or html page. blob could be of a jpg, gif, pdf, doc, txt, bmp, etc.

what i am doing is uploading a file (using apache DiskFileUpload), then gettin bytes (using fileItem.get()) and store it into DB in a blob field.

any suggestions...
thanx
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First you have to understand that images displayed "within" an HTML or JSP page are actually downloaded as seperate requests. You need to coordinate this request to whatever is going to supply the image (i.e. a servlet). So the HTML or JSP has some image tag in it:

In that tag, "getImage.do" is what we have our image servlet mapped to in our app server and "?id=5" is a request parameter specifying that the image id is 5 (unfamiliar with servlets? get reading).
The servlet gets the request parameter "id" out of the request object it is passed in its doGet() or doPost() methods. Use that index to look up the appropriate image in the database. ResultSet has a getBinaryStream() method so we read out of that stream and write to the servlet response object's OutputStream. Use the servlet response object's setContentType() method to the MIME Type of the image (i.e. "image/gif") for GIF images). The browser downloads the image and displays it. Simple, eh?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!