Error while uploading Image and Video File together !
- Dominant language
- JavaScript
- Stars
- 12.1k
- Forks
- 1.1k
- Avg merge
- 8d 2h
- Merged PRs (30d)
- 21
Description
Form Data

**This is the code to upload image and upload video**
`
const imageStorage = multer.diskStorage({
destination: "./assets/Images",
filename: (req, file, cb) => {
cb(
null,
"Image-" +
file.originalname.split(".")[0] +
"-" +
Date.now() +
"." +
file.originalname.split(".")[1]
);
},
});
const upload_image = multer({
storage: imageStorage,
limits: {
fileSize: 10000000,
},
fileFilter(req, file, cb) {
if (!file.originalname.match(/\.(png|jpg|JPG|PNG|webp|WEBP)$/)) {
return cb(new Error("Only Png / Jpg / Webp format is accepted"));
}
cb(undefined, true);
},
});
const videoStorage = multer.diskStorage({
destination: "./assets/Videos",
filename: (req, file, cb) => {
cb(
null,
"Video-" +
file.originalname.split(".")[0] +
"-" +
Date.now() +
"." +
file.originalname.split(".")[1]
);
},
});
const upload_video = multer({
storage: videoStorage,
limits: {
fileSize: 100000000,
},
fileFilter(req, file, cb) {
if (!file.originalname.match(/\.(mp4|mov)$/)) {
return cb(new Error("Only mp4 / mov format is accepted"));
}
cb(undefined, true);
},
});
`
**Code of the request**
`router.post(
"/add-image-video-post",
upload_image.fields([{ name: "Image", maxCount: 1 }]),
upload_video.fields([{ name: "Video", maxCount: 1 }]),
async (req, res) => {
console.log(req.files);
return res.status(200).json({ success: true });
}
);
`
**Error Image**

**Error Text**
**Error: Unexpected end of form
at Multipart._final (C:\Users\Hp\Desktop\twitter\backend\node_modules\busboy\lib\types\multipart
.js:588:17)
at callFinal (node:internal/streams/writable:694:27)
at prefinish (node:internal/streams/writable:723:7)
at finishMaybe (node:internal/streams/writable:733:5)
at Multipart.Writable.end (node:internal/streams/writable:631:5)
at onend (node:internal/streams/readable:693:10)
at processTicksAndRejections (node:internal/process/task_queues:78:11)
**
Contributor guide
Assessment
This issue has not been assessed yet.