This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Struts and the fly likes Saving binary data as images on the client machine Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Reply Bookmark "Saving binary data as images on the client machine" Watch "Saving binary data as images on the client machine" New topic
Author

Saving binary data as images on the client machine

Srikanth Madasu
Ranch Hand

Joined: Sep 10, 2008
Posts: 48

Hi All, I have an application where user uploads a file and then we need to process the file and after that pull some images from from DB(binary data) and save this data as images on the client machine. I have some prob in saving the images on client machine.

I am using the following code in my action class : but this saves files on the server :



I did some research and found that ServletOutputStream is actually used in downloading files from server to client. But I am not sure if I could use this class to save the binary data.

Any help would be greatly appreciated

Thanks in advance..

--Srik
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56529
    
  14

You cannot directly write files to a client system. Think of the nightmarish security implications if you could!

Rather, you must make the file available for download, and the user can choose to save the file or not.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Yes, you could write it to the servlet's output stream to send it to the client (after sending the appropriate Content-type header), but if you're using Struts 2, you can use the stream result (struts 2 stream result)!
Srikanth Madasu
Ranch Hand

Joined: Sep 10, 2008
Posts: 48

Thank you guys for your replies..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Saving binary data as images on the client machine
 
Similar Threads
Problem in writing any double in a file
problem with DataInputStream
problem with writing file , please help
Code in servlet - doubt
Client Issue