我在 cli 脚本中有这个 nodejs 代码。我正在尝试从一系列链接下载一些图像,但总是出现此错误:
TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of IncomingMessage
这是代码:
imagesLinks.forEach( (link) => {
let filename = path.basename(link);
let outputDir = path.format({dir: __dirname, base: `/dadini/${filename}`});
https.get(link, (res) => {
fs.writeFileSync(outputDir, res);
});
});
如何从链接中正确获取图像并将其传递给 writeFileSync
函数?