我尝试使用https.get
下载多张图片,但是得到了
错误[ERR_STREAM_WRITE_AFTER_END]:结束后写入
function downImageTour(paths) {
for (i = 0; i < paths.length; i++) {
var arraySplitImage = paths[i].split(".");
var name_image = uuid.v4() + '.' + arraySplitImage[arraySplitImage.length - 1];
var file = fs.createWriteStream("./" + config.USER.IMAGE_FORDER_AVATAR + "/" + name_image);
var request = https.get(paths[i], (response) => {
response.pipe(file);
let urlAvatar = config.PROTOCOL_URL + config.URL_DOMAIN + ":" + config.PORT + config.USER.IMAGE_TOUR_RESPONSE + "/" + name_image;
file.on('finish', function () {
res.send({ urlRes: urlAvatar });
file.close();
});
});
}
}
有什么解决办法吗? 谢谢。