express (using multer) Error: Multipart: Boundary not found, request sent by POSTMAN

user9150719 picture user9150719 · Apr 6, 2018 · Viewed 32.3k times · Source

Notice: only when I use form-data body form in Postman (which is the form I have to use because I want to send files beside text fields), I get:

Error: Multipart: Boundary not found.

when I use x-www-form-urlencoded everything is ok. (ofcourse when body-parser is used as middleware)

This is Request Content: (made by Postman)

POST /test HTTP/1.1
Host: localhost:3000
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
Cache-Control: no-cache
Postman-Token: 61089a44-0b87-0530-ca03-a24374786bd1

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="test"

a simple word
------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="data"

good
------WebKitFormBoundary7MA4YWxkTrZu0gW--

index.js:

var express = require('express');
var app = express();

var multer = require('multer');
var upload = multer();

app.post('/test', upload.array(), function (req, res, next) {
    console.log(req.body.test);
    console.log(req.body);
});

app.listen(3000, function () {
    console.log('app started');
});

Answer

user9150719 picture user9150719 · Apr 6, 2018

I found the solution. I only had to prevent Postman to send a Content-Type header. So I just removed it from request headers.