multer: Unexpected end of form at Multipart._final
Getting this error while using multer with react.js and node.js
Unexpected end of form
at Multipart._final (E:\nearme\backend\node_modules\busboy\lib\types\multipart.js:588:17)
at callFinal (internal/streams/writable.js:610:10)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
storageErrors: []
}
react.js file
const fd = new FormData();
fd.append("profile", data.profile);
fd.append("name", data.name);
fd.append("email", data.email);
fd.append("password", data.password);
const res = await axios.post("http://localhost:8000/signup/data", fd, {
headers: { "Content-Type": "multipart/form-data" },
});
node js file:
const multer = require("multer");
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, "../public");
},
filename: function (req, file, cb) {
const uniqueSuffix = Date.now() + "-" + Math.round(Math.random() * 1e9);
cb(null, file.fieldname + "-" + uniqueSuffix);
},
});
const upd = multer({ storage: storage }).single("profile");
router.post("/data", (req, res) => {
upd(req, res, function (err) {
if (err instanceof multer.MulterError) {
console.log("A Multer error occurred when uploading");
} else if (err) {
console.log("An unknown error occurred when uploading", err);
}
});
});
For more details about project refer this https://github.com/amulagrawal02/nearme
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 33
- Comments: 36 (2 by maintainers)
Links to this issue
Commits related to this issue
- downgraded multer https://github.com/expressjs/multer/issues/1144 — committed to Oneirocom/Magick by Knar33 a year ago
- downgraded multer https://github.com/expressjs/multer/issues/1144 — committed to Oneirocom/Magick by Knar33 a year ago
- downgraded multer https://github.com/expressjs/multer/issues/1144 — committed to Oneirocom/Magick by Knar33 a year ago
- https://github.com/expressjs/multer/issues/1144 — committed to uacanada/nodebb-plugin-uacanadamap by Vik-BC 10 months ago
- https://github.com/expressjs/multer/issues/1144 — committed to uacanada/nodebb-plugin-uacanadamap by Vik-BC 10 months ago
- downgraded multer https://github.com/expressjs/multer/issues/1144 — committed to Oneirocom/Magick by Knar33 a year ago
I have the same issue đŚ
We had a similar issue on
1.4.5-lts.1
and1.4.4-lts.1
. Downgrading to1.4.3
fixed the issue for us. NOTE:1.4.3
has an outstanding security issue due todicer
.For people still experiencing this issue, I found a similar bug when using
multer
orbusboy
in a Google Cloud Function with an express router.I found an answer that fixed the issue for me here: https://github.com/mscdex/busboy/issues/296#issuecomment-1107458297
I believe
multer
is usingreq.pipe
in the middleware, which may be causing the issue. I am still trying to make multer work with our Cloud Function with no luck. So I am using busboy withbb.end(req.rawBody)
instead.Hope this helps!
I have the same issue
My problem was this line:
replaced it by
and it worked.
i also have the same issue and nothing here seems to work
Iâm having the same issue, there should be a more convenient way than downgrading (Iâm on
1.4.5-lts.1
), in my case I do have body-parser as itâs needed on other routes so that might collide with multer? I tried settingbodyparser.urlencoded({extended:true})
before the multer middleware as mentioned here but that didnât solve it for me, itâs strange because I canât reproduce this locally, this only happens on our live environments. Kindly asking for help on this one, here is the full issue: https://stackoverflow.com/questions/76064309/unexpected-end-of-form-at-callfinal-errorCan confirm, that it works with a downgrade to
1.4.3
⌠Btw: with the current version of busboy1.6.0
the same error occurs.if youâre reading this because you get an uncaughtException âUnexpected end of formâ the root cause is that the multer code removes the busboy error listener too early, the fix is in https://github.com/expressjs/multer/pull/1177. It would be great the Multer team merges it as it is trivial to repro the issue.
For NextJS, you just have to add this code at the top of the file.
export const config = { api: { bodyParser: false } };
Yes! downgrading to multer 1.4.3 worked! thanks
Is there any plan to fix this? Itâs just quite ugly having to use busboy for this compare to a nice decorator
I just make another method to upload files that are not related to Multer instead you can use existing packages to do that
This is a demo that you can run and get the result also after upload you can check the file if it was ok and then rename otherwise delete this or something else here in their full doc of https://www.npmjs.com/package/multiparty
Note: Ignore another thing that I use in my frontend request demo just see how I send the request đ
Kindly solve this issue the only solution i found is downgrading to version @1.4.2, but this version contains a severe levels of security issues.
Yes! downgrading to multer 1.4.3 worked! thanks great