Serving Temporary Files with NodeJs

后端 未结 2 2104
礼貌的吻别
礼貌的吻别 2021-02-04 09:52

I am building a NodeJs SOAP client. Originally, I imagined the server (ie the node SOAP client) would allow downloading documents through a REST API (the REST API is authentica

2条回答
  •  清歌不尽
    2021-02-04 10:07

    If you are visiting this SO page after Dec 2015, you may find that the previous solution isn't working (At least it isn't working for me). I found a different solution so I thought I would provide it here for future readers.

    app.get('/download', function(req, res){
        res.download(pathToFile, 'fileNameForEndUser.pdf', function(err) {
            if (!err) {
                fs.unlink(path);
            }
        });
    });
    

提交回复
热议问题