, когда я пытаюсь сохранить без изображения, он показывает следующую ошибку "" message ":" Не удается прочитать свойство 'путь' из неопределенного ".?"
// product controller
exports.products_create_product = (req, res, next) => {
const product = new Product({
_id: new mongoose.Types.ObjectId(),
name: req.body.name,
price: req.body.price,
productImage: req.file.path
});
product
.save()
.then(result => {
console.log(result);
res.status(201).json({
message: "Created product successfully",
createdProduct: {
name: result.name,
price: result.price,
_id: result._id,
request: {
type: "GET",
url: "http://localhost:3000/products/" + result._id
}
}
});
})
.catch(err => {
console.log(err);
res.status(500).json({
error: err
});
});
};
// Ниже приведены маршруты моего продукта
router.post("/", checkAuth, upload.single('productImage'),
ProductsController.products_create_product);