📌  相关文章
📜  nodejs 从缓冲区发送下载文件 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:09.203000             🧑  作者: Mango

代码示例1
var stream = require('stream');
//...
app.get('/download', function(request, response){
  //...
  var fileContents = Buffer.from(fileData, "base64");
  
  var readStream = new stream.PassThrough();
  readStream.end(fileContents);

  response.set('Content-disposition', 'attachment; filename=' + fileName);
  response.set('Content-Type', 'text/plain');

  readStream.pipe(response);
});