Am developing an API for taking input information like title, description, and image or document. I have tested the API is working when I don't add the image/document part. How can I add this field to insert an image/document to the mongo DB? I can actually add info without the image/docs upload, How do I go about it?
Upload info controller
exports.upload = (req, res) =>{
const { title, category, duration, durationSys, description } = req.body
Project.findOne({ title }).exec((err, project) => {
if (project) {
return res.status(400).json({
error: 'Choose a unique title for your Project'
});
}
});
let newProject = new Project({ title, category, duration, durationSys, description});
newProject.save((err, success) => {
if (err) {
console.log('ADDING PROJECT ERROR', err);
return res.status(400).json({
error: err
});
}
res.json({
message: 'Added successfully, check your projects'
});
});
};