How to upload a Image and a Video file to different destination recieved via same request .
- Dominant language
- JavaScript
- Stars
- 12.1k
- Forks
- 1.1k
- Avg merge
- 8d 2h
- Merged PRs (30d)
- 21
Description
Destination For Image Storage
`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);
},
});
`
Destination For Video Storage
`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);
},
});`
I am doing this but this is giving me error
`router.post(
"/add-image-video-post",
upload_image.array("Image", 1 ), upload_video.fields("Video", 1 ) ,
async (req, res) => {
console.log(req.files);
return res.status(200).json({ success: true });
}
);
`

Contributor guide
Assessment
This issue has not been assessed yet.