• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need to convert oracle blob into a file

 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic