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

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

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

我得到的URL和文件名变量,但我如何设置标题'内容处置','附件'; 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();
  }

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

上一篇: Download file from NodeJS server adding header for content disposition

下一篇: Chrome not recognising attachment filename