Dynamically creating a file with node.js and make it available for download

后端 未结 1 1746
北海茫月
北海茫月 2020-12-18 06:15

I am building a text editor in Node.js where a user create a file in a textarea. When he is done editing the file, he can push an \"export\" button that triggers a Jquery fu

相关标签:
1条回答
  • 2020-12-18 07:04

    I tested this on my server and it worked. It was from a GET call but I don't see why it wouldn't work with a POST.

    res.setHeader('Content-disposition', 'attachment; filename=theDocument.txt');
    res.setHeader('Content-type', 'text/plain');
    res.charset = 'UTF-8';
    res.write("Hello, world");
    res.end();
    
    0 讨论(0)
提交回复
热议问题