http 서버에서 multipart/form-data에 boundary 넣는 방법

const express = require('express');
const FormData = require('form-data');

let router = express.Router();

router.route('/test').get((req, res) => {
  let form = new FormData();
  form.append('part1', 'part 1 data');
  form.append('part2', 'part 2 data');
  form.append('part3', 'part 3 data');
  
  res.setHeader('Content-Type', `multipart/form-data; boundary=${form.getBoundary()}`);

  form.pipe(res);
});

module.exports = router;

그리고 http://127.0.0.1/test를 postman으로 호출하면 다음과 같은 결과를 얻게 된다.

----------------------------858572202552762304269725
Content-Disposition: form-data; name="part1"

part 1 data
----------------------------858572202552762304269725
Content-Disposition: form-data; name="part2"

part 2 data
----------------------------858572202552762304269725
Content-Disposition: form-data; name="part3"

part 3 data
----------------------------858572202552762304269725--

헤더는 다음과 같다.

X-Powered-By →Express
Access-Control-Allow-Origin →*
Content-Type →multipart/form-data; boundary=--------------------------858572202552762304269725
Set-Cookie →connect.sid=s%3AfR2I5ZqdGR4Ijy9hzQil9yOuZocESKC_.y9bQSZmnx8FvfScPTYsY1qpxgw%2Bu5MG6VuvS8SQ%2Bxmk; Path=/; HttpOnly
Date →Tue, 29 Oct 2019 05:47:50 GMT
Connection →keep-alive
Transfer-Encoding →chunked