6

すべての PDF ファイルはサーバー上のファイルシステムに保存されます。ファイルをクライアント側でダウンロードできるようにする方法。

例:

 app.use('/pdfDownload', function(req, res){
  var pathToTheFile = req.body.fileName;
   readFile(pathToTheFile, function(data){
      //code to make the data to be downloadable;
    });
 });

リクエストはありますか

function readFile(pathToTheFile, cb){
   var fs = require('fs');
   fs.readFile(pathToTheFile, function(err, data){
      //how to make the file fetched to be downloadable in the client requested
      //cb(data);
   }); 
}
4

1 に答える 1

8

を使用express.staticして、アプリの早い段階で設定できます。

app.use('/pdf', express.static(__dirname + '/pathToPDF'));

ブラウザが「/pdf/fooBar.pdf」などに移動すると、自動的にジョブが実行されます。

于 2013-07-24T11:12:44.227 に答える