i'm trying to save the mulptile fields of files in mongodb with the use of multer,As im using form-data for selecting files. As per name fields file {name:'thumbnail'},{name:'trailer'},{name:'lessons'}] so i'm passing same in the postman but it showing an error: MulterError: Unexpected field
Where i'm passing wrong ,please help me thanks in advance
schema:-
mongoose.Schema(
{
category:{ type: String },
courseBy:{ type: String },
thumbnail: { type: String, data:Buffer},
about: { type: String },
price : { type: String },
is_free : { type:Boolean, default: false },
tags : { type: String },
comments : { type: String },
ratings : { type: String },
hours: { type : String },
trailerVideo : {
title:{ type:String },
video: {
type:String,data:Buffer
}},
ratingCount : { type: Number},
lessons : [{
_id: false,
title : { type:String },
video : { type:String,data:Buffer },
}]
}
)
creating an instane:-
const trailer = {
title: req.body.title,
video: req.files.trailer[0].path,
}
const lessons = [{
title: req.body.title,
video: req.files.lessons[0].path
}]
const { category, courseBy, about, price, hours } = req.body
const courseFields = new Courses({
category: category,
courseBy: courseBy,
thumbnail: req.files.thumbnail[0].path,
about: about,
price: price,
hours: hours,
ratingCount : 0,
ratings : 0.0,
trailerVideo: trailer,
lessons: lessons
});
multer file
const multer = require("multer"),
storage = multer.diskStorage({
destination: function(req, file, cb) {
cb(null, 'uploads')
},
filename: function (req, file, cb) {
cb(null, file.originalname);
}
});
const uploadImg = multer({storage: storage}).fields([{name:'thumbnail'},{name:'trailer'},{name:'lessons'}]);
