We did it with ReactJS(front) and ASP.Net core(back) So the best way to do it is using FormData, We use an object like below that contains an array of objects, each object includes an array of images too,
{
CommodityID:xxxxx,
TotalWeight:xxxx,
CostOfCommodity:xxxx,
Prerequisites:[{
ProductId: xxxx,
DeliveryWeight: xxxxx,
ReleasedImagesUrl: [
multiple images file
]
},{
ProductId: xxxx,
DeliveryWeight: xxxxx,
ReleasedImagesUrl: [
multiple images file
]
}]
}
Actually, we send each item of the array separately like Prerequisites[0].DeliveryWeight
and this is the point. please pay attention to the letters that in our case first characters of items were capital (this is important too)
const formData = new FormData();
formData.append("CommodityID", this.state.commodityId);
formData.append("TotalWeight", this.state.totalWeight);
formData.append("CostOfCommodity",this.state.costOfCommodity);
for (let i = 0; i < this.state.prerequisitesListTemp.length; i++) {
formData.append(
`Prerequisites[${i}].ProductId`,
this.state.prerequisitesListTemp[i].productId
);
formData.append(
`Prerequisites[${i}].DeliveryWeight`,
this.state.prerequisitesListTemp[i].deliveryWeight
);
for (
let j = 0;j < this.state.prerequisitesListTemp[i].releasedImagesUrl.length;j++
) {
formData.append(
`Prerequisites[${i}].ReleasedImagesUrl`,
this.state.prerequisitesListTemp[i].releasedImagesUrl[j]
);
}
}