【发布时间】:2014-12-03 21:51:34
【问题描述】:
我尝试过一百万种方式下载这张图片,但我总是在 NodeJS 中得到一个未定义的值,有人可以帮助我吗!图片确实下载了,但我不能用它做任何事情,所以它基本上变得没用了!
var rawImg = urlHtml('img').attr('src'); // got the image needed!
var download = function (rawImg, filename, callback) {
request.head(rawImg, function (err, res, body) {
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(rawImg).pipe(fs.createWriteStream(__dirname + '/public/img/test.jpg')).on('close', function(callback) {
console.log(callback); // always getting undefined
});
});
};
download(rawImg, function () {
console.log('done'); // doesn't even launch because gets undefined before
});
【问题讨论】:
-
你在用什么样的
sorcery回调???