I am using scala and play framework to create an API server. On one of my API calls, I upload a JSON and after some meddling on the server, I send back an XML. This XML should then be downloaded as a text file and I figured it was easiest if I directly start a download in the backend and don't just create the file in the front-end.
I have successfully created the XML I wanted using the scala.xml
package and I do have now a node
object, that when printed looks strikingly like the XML I am looking for.
Scala's scala.xml.XML
object has a method, aptly called save
that allows me to make a file out of the XML. I could use that to create my XML, but that means that I have to save it on the hard drive, which is its own can of worms. But I am kind of dead in the water in how to save the file in RAM. Can anyone help me out here?
EDIT 1:
To clarify, on the front-end side I am calling this API with axios. At my user's computer, there should be a downloading dialogue opening, asking my user where to save the file which might be called foo.xml
. As I understand it, I need to transform my XML into a file stream. I can do this easily by just saving it on the hard drive and use java.nio
on it, but I was hoping there was a way to avoid the write on the hard drive just to read it back into a file stream and then delete it routine.