类型错误:“数据”参数必须是字符串类型或 Buffer、TypedArray 或 DataView 的实例。收到一个 IncomingMessage 的实例

时间:2021-03-09 11:04:03

标签: javascript node.js arrays

我在 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 函数?

0 个答案:

没有答案