DEV Community

Amul Agrawal
Amul Agrawal

Posted on

Multer Error

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" },
});`
Enter fullscreen mode Exit fullscreen mode

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);
}
});
});

Top comments (1)

Collapse
 
brightmiledaniel profile image
Daniel Benedek

Have you found a fix for this?