在 POST 请求中创建文件以供即时下载
create file for download on the fly within POST request
我想知道是否可以创建一个文件而不将其存储在驱动器中,仅用于在 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);
};
如果可能的话如何实现
download
方法明确设计用于传输 "the file at path"。
您可以使用一些数据创建下载,但您不能使用该方法。
res.set('Content-Type', 'text/xml');
res.set('Content-Disposition', 'attachment; filename="example.xml"')
res.send(xmlString);
我想知道是否可以创建一个文件而不将其存储在驱动器中,仅用于在 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);
};
如果可能的话如何实现
download
方法明确设计用于传输 "the file at path"。
您可以使用一些数据创建下载,但您不能使用该方法。
res.set('Content-Type', 'text/xml');
res.set('Content-Disposition', 'attachment; filename="example.xml"')
res.send(xmlString);