Multer rejects an upload because the multipart boundary is missing
Error: Multipart: Boundary not foundShort answer
A multipart body is split by a boundary string that must be announced in the Content-Type header. The error means the header reached the server without a boundary. This happens when a client sets Content-Type: multipart/form-data by hand, or sends a body that is not built as form-data at all.
Fix it fast
1Find out which cause you have
Send the failing request again and look at the Content-Type header the server really receives. A correct one looks like multipart/form-data; boundary=something.
app.post('/upload', (req, res, next) => { console.log(req.headers['content-type']); next(); }, upload.single('photo'), (req, res) => res.sendStatus(200));2Match what you see, then jump to its fix
- 1
The logged header is exactly multipart/form-data, with no boundary after itThe client set the multipart Content-Type header itselfFix - 2
The header has no boundary, and the request was built from a JSON object, raw text or a URL-encoded formThe body is not a multipart body, but the header says it isFix
- 1
What does the error look like?
Error: Multipart: Boundary not found
Cause 1 of 2
The client set the multipart Content-Type header itself
1Check
The boundary is a parameter of the Content-Type header, and the client picks a fresh value for each request. If you type the header by hand (in a request builder, an axios config or a fetch call), you cannot know the value, so the part after the semicolon is missing.
grep -rn "multipart/form-data" src/ client/ 2>/dev/null2Fix
Delete the manual Content-Type header and pass a FormData object as the body. The HTTP client then writes the header with its own boundary.
const form = new FormData();
form.append('photo', fileInput.files[0]);
await fetch('/upload', { method: 'POST', body: form });
// no headers: { 'Content-Type': ... } here3Verify
The logged header now contains boundary=, and Multer fills req.file.
console.log(req.headers['content-type'], req.file);Confirmed by rfc-editor.org
Cause 2 of 2
The body is not a multipart body, but the header says it is
1Check
A multipart body is a series of parts separated by the boundary line. A JSON string or an urlencoded string with a multipart header on top is not that format, so there is nothing to split.
curl -s -o /dev/null -w '%{http_code}\n' -X POST http://localhost:3000/upload -F photo=@./test.jpg2Fix
Build the request as form-data in your client (in a request builder, choose the form-data body type, not raw), and give the file field the same name that Multer expects.
const multer = require('multer');
const upload = multer({ dest: 'uploads/' });
app.post('/upload', upload.single('photo'), (req, res) => {
res.json({ file: req.file?.originalname });
});3Verify
The curl command above returns 200 and the file lands in uploads/.
ls uploads/Confirmed by rfc-editor.org
How do I stop it coming back?
- Never write the multipart Content-Type header by hand; let the client library create it.
- Keep one upload helper in the front end, so every upload goes through the same FormData code.
- Test uploads with a real file from the command line before debugging the browser.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Multer upload fails with 'Unexpected end of form'
Error: Unexpected end of form
Multer reads multipart bodies with busboy, which raises this error when the request body ends before the closing boundary line.
2 causes, each with a fixBack end
Uploaded files are missing from the request in Express
MulterError: LIMIT_UNEXPECTED_FILE
Express does not parse file uploads itself, and Multer only handles multipart/form-data.
4 causes, each with a fixBack end
Multer rejects the upload with Unexpected field
MulterError: Unexpected file field
Multer throws LIMIT_UNEXPECTED_FILE when a file arrives under a field name your route did not declare, or when more files arrive than the route allows.
4 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fixBack end
bcrypt.hash throws 'data and salt arguments required'
Error: data and hash arguments required
The bcrypt package throws this when hash gets null or undefined for the password or for the salt.
4 causes, each with a fix