我试图弄清楚,如果可能的话,创建一个文件而不将其存储在驱动器中,只是为了在POST请求中立即下载它。
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);
};如果有可能的话
发布于 2020-03-17 08:11:29
download方法显式地设计为传输“路径上的文件”。
您可以使用一些数据创建下载,但不能使用该方法。
res.set('Content-Type', 'text/xml');
res.set('Content-Disposition', 'attachment; filename="example.xml"')
res.send(xmlString);https://stackoverflow.com/questions/60718417
复制相似问题