• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Document Retrival from database.

 
Vishal Kumar Aruru
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a requirement of uploading the file like .doc, .xls, .jpeg, .txt, .gif, .pdf into database. so, i uploaded the file by converting them into bytearray and then to database like blob. Up to here it is fine. My problem is view the file. i.e. i know the file extension and i will get the byteArray from the database to the presentation layer. I need a logic such that i can use this byteArray and file extension to show the file like for example, if i upload a image, it converts to bytearray and then to blob to database. then i retrieves the bytearray from the database and i have to convert this byte array to image. similarly to .doc, .xls, .jpeg, .txt, .gif, .pdf.

Thanks in Advance.
 
Ronald de Gier
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you perhaps create a temp file with the given extension, stream the bytes in, and launch the proper application with the filename as parameter?
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ronald de Gier wrote:launch the proper application with the filename as parameter?

Using Desktop.open of course.
 
Vishal Kumar Aruru
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not understanding what you are saying, i will get a raw byte array, and how can i make generic one to open the file, i am bit confused, can you tell me scenario or any junk code such that i feel comfortable.
thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key question is, what do you intend to do with those files? Stream them to the client? Show a preview? Process them on the server?
 
Vishal Kumar Aruru
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your concern,

I want to show preview, thats it
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Preview for random file types is tough. Images are easy (load them using ImageIO.read, scale the BufferedImage to your heart's content, save it to a public directory, and embed it in the page); but everything else is a different story.

The PDF-Renderer library can display PDFs in a Swing component; you should be able to render that into a BufferedImage, at which point it's the same as what I mentioned above for images in general.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic