Reputation: 1564
I am trying to figure out, if its possible to create a file without storing it in the drive, for only purpose to download it right away within POST request.
const specialRequests = async (req, res, next) => { // POST request
... // processing
let xmlString = ... // get processed xml string
// create xml file from that xmlString
// initialise download of the file, dont save it
let file = ???
res.download(file);
};
If its possible how it can be done
Upvotes: 1
Views: 554
Reputation: 944530
The download
method is explicitly designed to transfer "the file at path".
You can create a download with some data, but you can't use that method.
res.set('Content-Type', 'text/xml');
res.set('Content-Disposition', 'attachment; filename="example.xml"')
res.send(xmlString);
Upvotes: 3