Download file from NodeJS server adding header for content disposition

I have this server function that extract URL and Filename to files saved on external services.

Example - https://ec-media.sndcdn.com/ZtPlxyZHyzxy.128.mp3?f10880d39085a94a0418a7ef69b03d522cd6dfee9399eeb9a522059d69ffb9359bc7c231696809f40c29ddb8e488adfa7f7fccde067c557b3ae31730fc6901d18842314a30

I get url and filename to variables, but how do I set header 'Content-disposition', 'attachment'; filename = filename; and return it to client so it'll be downloadable with click.

// load future from fibers
var Future = Meteor.npmRequire("fibers/future");
// load youtubedl
var youtubedl = Meteor.npmRequire('youtube-dl');
// load fs
var fs = Meteor.npmRequire('fs');
// require request
var request = Meteor.npmRequire('request');

Meteor.methods({
  'command' : function(line) {
    // this method call won't return immediately, it will wait for the
    // asynchronous code to finish, so we call unblock to allow this client
    this.unblock();
    var future = new Future();

    youtubedl.getInfo(line, function(err, stdout, stderr) {
      var url = stdout.url;
      var filename = stdout._filename;

      future.return({stdout: stdout, stderr: stderr});
    });
    return future.wait();
  }

});
链接地址: http://www.djcxy.com/p/46830.html

上一篇: 在HTTP标头中处理(c#)

下一篇: 从NodeJS服务器下载文件添加标头以进行内容处置