Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Stream file to client that exists only in memory?

 
Rob Hyx
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the contents of a file that I have constructed in memory by basically using String.getBytes(); and then passing that into a ByteArrayInputStream. I then read the bytes and stream them out via ServletOutputStream. The text reaches the client because I see the response in Firebug, the only problem is, is that it's not a file. I set the response like:



The call is made asynchronously. Any idea what I am doing wrong? I want there to be a prompt for the user to either save or open the file in the appropriate application.

Thanks in advance!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A response is a response; it's never a file. You've set the content disposition to tell the browser your intentions. What happens then is usually up to the browser and/or the user's settings.

Have you tried it in different browsers to observe the behavior?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64632
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. The fact that the response data originally existed only in memory is completely moot. The browser has no idea how the data originated and couldn't care less.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic