Skip to content
Jaroslav Závodný edited this page Jul 21, 2018 · 1 revision

How a HTTP multipart request looks like

POST HTTP/1.1
Host: localhost:8080
Content-Type: multipart/form-data; boundary=[boundary]

--[boundary]<CR><LF>
Content-Disposition: form-data; name="file"; filename="01.png"<CR><LF>
Content-Type: image/png<CR><LF>
<CR><LF>
[Content data]<CR><LF>
--[boundary]<CR><LF>
Content-Disposition: form-data; name="file"; filename="02.png"<CR><LF>
Content-Type: image/png<CR><LF>
<CR><LF>
[Content data]<CR><LF>
--[boundary]--<CR><LF>

Node.js request body

// The request object that's passed in to a handler implements
// the ReadableStream interface. This stream can be listened to
// or piped elsewhere just like any other stream. We can grab
// the data right out of the stream by listening to the stream's
// 'data' and 'end' events.
// The chunk emitted in each 'data' event is a Buffer.

// See more in Node.js official docs:
// https://nodejs.org/en/docs/guides/anatomy-of-an-http-transaction/

req.on('data', function (data) {
  parser.add(data)
})

req.on('end', function () {
  parser.end()
})
Clone this wiki locally