I\'m using the Request module to download files, but I\'m not quite sure how to pipe the response to an output stream when the filename must come from the \'Content-Disposition\
I'm reqesting a image from yahoo and it isn't using the content-disposition
header but I am extracting the date
and content-type
headers to construct a filename. This seems close enough to what you're trying to do...
var request = require('request'),
fs = require('fs');
var url2 = 'http://l4.yimg.com/nn/fp/rsz/112113/images/smush/aaroncarter_635x250_1385060042.jpg';
var r = request(url2);
r.on('response', function (res) {
res.pipe(fs.createWriteStream('./' + res.headers.date + '.' + res.headers['content-type'].split('/')[1]));
});
Ignore my image choice please :)