How to send a pdf file from Node/Express app to the browser

后端 未结 5 2038
悲&欢浪女
悲&欢浪女 2020-12-06 00:06

In my Node/Express app I have the following code, which suppose to read a PDF document from a file, and send it to the browser:

var file = fs.createReadStrea         


        
5条回答
  •  [愿得一人]
    2020-12-06 00:44

    Best way to download a PDF on REST API call.

    var path = require('path');     
    var file = path.join(__dirname, 'file.pdf');    
    res.download(file, function (err) {
           if (err) {
               console.log("Error");
               console.log(err);
           } else {
               console.log("Success");
           }    
    });
    

提交回复
热议问题