there is my frontend code in react js .....
const onClickHandler = () => {
const data = new FormData()
for(var x = 0; x<selectedFile.length; x++) {
data.append('file', selectedFile[x])
}
let post = state.postData
data.append("obj", JSON.stringify(post))
Axios.post("http://localhost:4000/postImages", data)
.then(res => console.log("response>>>",res))
}
there is my nodeJs server code and it is work correctely and give me correct response.....
router.post("/", upload, function(req, res, next) {
const obj = JSON.parse(req.body.obj)
let postData = {
file: req.files,
data: obj,
};
res.send(postData)
});
but when i am use schema with above node js code then accord error in respons that is "xhr.js:184 POST http://localhost:4000/postImages 500 (Internal Server Error)". there is show in below "error Code"
router.post("/", upload, function(req, res, next) {
const obj = JSON.parse(req.body.obj)
let newPostData = new newPostSchema({
id: obj.id,
name: obj.name,
price: obj.price,
salePrice: obj.salePrice,
discount: obj.discount,
pictures: obj.pictures,
shortDetails: obj.shortDetails,
description: obj.description,
stock: obj.stock,
new: obj.new,
sale: obj.sale,
category: obj.category,
colors: obj.colors,
size: obj.size,
tags: obj.tags,
rating: obj.rating,
variants: obj.variants,
});
let postData = {
file: req.files,
data: newPostData,
};
res.send(postData)
});
here is my code schema .....
const mongoose = require("mongoose");
const newPost_Schema = new mongoose.Schema(
{
id: Number,
name: String,
price: Number,
salePrice: Number,
discount: Number,
pictures: [String],
shortDetails: String,
description: String,
stock: Number,
new: Boolean,
sale: Boolean,
category: String,
colors: [String],
size: [String],
tags: [String],
rating: Number,
variants: [Object],
},
{
timestamps: true,
}
);
const newPostSchema = mongoose.model("newPost_data", newPost_Schema);
exports.newPostSchema = newPostSchema;