我有这个服务器功能,它将URL和文件名提取到保存在外部服务上的文件。
我获取了变量的url和filename,但是如何设置标题'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();
}
});