Request Parameters:
{
"project_name":"",
"city":"",
"street":"",
"property_type":[
{
"id":"1",
"property_type":"type",
"floor_plan_img":["1654513514684-download (2).jpg","1654513514684-download.jpg"]
},
{
"id":"2",
"property_type":"type",
"floor_plan_img":["1654513514684-download-1.jpg","1654513514684-new.jpg"]
}]
}
CODE
var propertyTypeInfo=[];
if(req.body.property_type_data && typeof(req.body.property_type_data) == 'string'){
propertyTypeInfo=JSON.parse(req.body.property_type_data)
console.log(typeof(propertyTypeInfo))
}else{
propertyTypeInfo=req.body.property_type_data
}
var floorPlanImgs=[];
if(req.files.floor_plan_img)
{
floorPlanImgs = req.files.floor_plan_img? req.files.floor_plan_img:'';
}
if(propertyTypeInfo.length >0){
for(let i=0;i<propertyTypeInfo.length;i++){
let data=[];
if(req.files.floor_plan_img[i].filename){
console.log('IMDATA');
var floorPlanImg = req.files.floor_plan_img.map(function(file) {
return file.filename;
});
if(floorPlanImg[i].length > 0){
console.log(floorPlanImg.length,'[i]floorPlanImg[i]');
for(let j=0;j<floorPlanImg[i].length;j++){
floorPlanImg = req.files.floor_plan_img.map(function(file) {
return file.filename; // or file.originalname
});
data.push(floorPlanImg[j]);
}
}
console.log(data[i],'floorPlanImgdata');
}
PropertyType.create({
property_type:propertyTypeInfo[i].property_type,
floor_plans_img:data[i],
})
}
}
Above are the request parameters and sample code of multer file upload. Here property type is an array of object ,inside property_type floor_plan_img is another array of files/images.
Trying to upload multiple array of images/files for repective property_type.But after iteration stroing storing single image/file for floor_plan_img field.
Can you please help me to resolve the issue. And share the form data postman request for multiple array of images/files.