Browser HTML Form
<form action="/multipart-data?id=x" method="post" enctype="multipart/form-data">
<b>multipart/form-data</b><br>
<span>jobid</span>
<input type="number" name="jobid" value="0"><br>
<span>jobname</span>
<input type="text" name="jobname" value=""><br>
<input type="submit"><br>
</form>
Server Express Router
import express from "express";
import bodyParser from "body-parser";
const router = express.Router();
router.post("/multipart-data",
log,
multer({ dest: 'uploads/' }).none(),
printBody
);
function log(req, res, next) {
console.log(req.method + ` ` + req.originalUrl);
next();
}
function printBody(req, res, next){
console.log(req.body);
console.log(req.query);
next();
}
export default router;
Terminal Output
POST /justdata
{ jobid: '0', jobname: 'asdf' }
{ id: 'x' }
Request Headers
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate, br
Accept-Language: en-CA,en-GB;q=0.9,en-US;q=0.8,en;q=0.7
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 234
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryB2AGWn1yYcOCi0T9
Request Body
------WebKitFormBoundaryB2AGWn1yYcOCi0T9
Content-Disposition: form-data; name="jobid"
0
------WebKitFormBoundaryB2AGWn1yYcOCi0T9
Content-Disposition: form-data; name="jobname"
sdf
------WebKitFormBoundaryB2AGWn1yYcOCi0T9--
1 Response
[…] Instead of the ampersand delimited string of parameters, the parameters are now delimited by the unique boundary string “——WebKitFormBoundaryB2AGWn1yYcOCi0T9“. The boundary string is chosen in such a way as it does not appear anywhere else in the body data. Normally the programmer does not need to worry themselves about it, it is generated automatically. The boundary string is send in the HTTP content-type request header, appended to the type by a semicolon. See implementation. […]