This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
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
Joined: Sep 09, 2009
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?
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.
Joined: Mar 22, 2005
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?
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.