Node.js - generate multipart/form-data

2020-07-23 03:43发布

问题:

Is there a Node.js library for generating multipart/form-data content in the following form?

------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="to"

destination@email.com
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="from"

recipient@email.com
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="subject"

subject line
------------------------------7a9cd2dc11c1
Content-Disposition: form-data; name="text"

This content does not matter.
------------------------------7a9cd2dc11c1--

回答1:

fermata looks like it might be what you're looking for. From the github page:

fermata.json("http://example.com/some/action").post({
  'Content-Type':"multipart/form-data"
}, {
  fileField: form.input.file || {data:nodeBuffer, name:"", type:""}
}, callback)


回答2:

request supports multipart/form-data or if you're just looking to create the content body, try form-data