node-fetch

How to send a file in request node-fetch or Node?

Deadly 提交于 2019-12-03 09:08:40
问题 How do I attach a file in Node or Node Fetch POST request? I am trying to invoke an API which will import a CSV or XLS file. Is this possible using Node or Node Fetch? 回答1: README.md says: Use native stream for body, on both request and response. And sources indicate it supports several types, like Stream , Buffer , Blob ... and also will try to coerce as String for other types. Below snippet shows 3 examples, all work, with v1.7.1 or 2.0.0-alpha5 (see also other example further down with

How to send a file in request node-fetch or Node?

南笙酒味 提交于 2019-12-03 03:17:54
How do I attach a file in Node or Node Fetch POST request? I am trying to invoke an API which will import a CSV or XLS file. Is this possible using Node or Node Fetch? README.md says: Use native stream for body, on both request and response. And sources indicate it supports several types , like Stream , Buffer , Blob ... and also will try to coerce as String for other types. Below snippet shows 3 examples, all work, with v1.7.1 or 2.0.0-alpha5 (see also other example further down with FormData ): let fetch = require('node-fetch'); let fs = require('fs'); const stats = fs.statSync("foo.txt");