0
我想讓http.get下載圖像文件列表。 我有一個for循環遍歷列表,並用代表保存位置的字符串填充變量file_savedest。 因此,http.get在每次循環迭代時都被調用,我如何將file_savedest提供給http.get,以便知道要下載和保存的文件。http.get循環下載文件列表
var file_savedest = dir+"/"+iname;
http.get(options, function(res){
var imagedata = '';
res.setEncoding('binary');
res.on('data', function(chunk){
imagedata += chunk
});
res.on('end', function(){
fs.writeFile(file_savedest, imagedata, 'binary', function(err){
if (err){
console.log(err);
} else {
console.log("File:" + file_savedest + " saved");
}
});
});
});