更新时间:2023-12-04 20:53:58
如果使用Iron Router,请在服务器上添加一条生成文本文件的路由,并设置适当的标头,并以生成的文件结束响应:
If using Iron Router, add a route on the server that generates the text file and set the appropriate headers and end the response with the file generated:
Router.map(function() {
this.route('txtFile', {
where: 'server',
path: '/text',
action: function() {
var text = "This is the awesome text.";
var filename = 'textfile' + '.txt';
var headers = {
'Content-Type': 'text/plain',
'Content-Disposition': "attachment; filename=" + filename
};
this.response.writeHead(200, headers);
return this.response.end(text);
}
})
});
在客户端上:
<a href="/text">Download text</a>