This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
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: 60774
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by 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
Code in servlet - doubt
Client Issue
problem with writing file , please help