我有这个服务器功能,它将URL和文件名提取到保存在外部服务上的文件 .

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

我得到url和filename到变量,但是如何设置 Headers 'Content-disposition','attachment'; filename = filename;并将其返回给客户端,以便点击即可下载 .

// 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();
  }

});