What is the problem in this script? When I want to upload an image I found this problem:
Error: ENOENT: no such file or directory, open 'C:UsershamzaDesktopMERN_Stack_Project_WeConnect_Social_Media-masterserverpublicuploadsprofile_pic1611529212065_0.jfif'
changeProfilePic(req, res) {
let profile_pic = req.file.filename
let loggedInUser = req.userDetails._id
let reqUserId = req.body.id
let oldPic = req.body.oldPic
if (oldPic !== "user.png") {
const filePath = `../server/public/uploads/profile_pic/${oldPic}`;
fs.unlink(filePath, (err) => {
if (err) { console.log(err) }
if (reqUserId === loggedInUser) {
userModel.findByIdAndUpdate(loggedInUser, {
profile_pic
}).exec((err, result) => {
if (err) { console.log(err) }
res.json({ result })
})
} else {
res.status(404)
}
})
} else {
if (reqUserId === loggedInUser) {
userModel.findByIdAndUpdate(loggedInUser, {
profile_pic
}).exec((err, result) => {
if (err) { console.log(err) }
res.json({ result })
})
} else {
res.status(404)
}
}
}
question from:
https://stackoverflow.com/questions/65876973/what-is-the-problem-in-this-script-when-i-want-to-upload-an-image 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…