Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Downloading XML stream  RSS feed

 
Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have an xml stream which we retrieve from the DB.
We need to allow the user to download this stream as a file onto their local system.
How do we convert this stream into a file in memory,which is then allowed to be downloaded by the user to a selected location on his machine.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could read from that stream and copy the data to a ByteArrayOutputStream. But back up a step. What makes you think you need a "file in memory"? Why can't you just read from that stream and download directly from there? If you are writing a web application (you didn't mention the context) then that's what you should do. Don't waste time and memory storing the data before downloading it.
 
Ranadhir Nag
Ranch Hand
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i wish the user to download the stream into a local file on the users machine machine,what do I give the 'Content-Disposition' as?

I thought of allowing the stream to be downloaded as a file:
'response.setHeader("Content-Disposition", "attachment;filename=data.txt");

Is there some other way to download the stream,without allowing it to be downloaded in te form of a file from the server?
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using the Content-Disposition header then you just have to write the data from the XmlStream to the output stream of the servlet.
In this scenario, the body of the response must contain the data as inline or multipart.
The file name specified in the Content-Disposition header is the name that must be used when the content is stored as a file by the client.
Hope this helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!