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.
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.
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.