ควรเขียน if !req.file ยังไงครับ

คือผมอัพโหลดรูปภาพได้ะ เเต่ติดอยู่ที่ว่าเวลาผมไม่อัพโหลดเเบบจะไม่ใส่ภาพ มันถามหา path มันบอก undefined เเต่อันอื่นไม่เป็นน่ะเว่ลาไม่ใส่เพิ่มได้ปกติ

router.post("/save",upload.single('image'),async(req, res, next) => {
  console.log(req.file);
 
  if (!req.file) {
      
      
  }
 
  const user = new User({
    
    username: req.body.username,
    password: req.body.password,
    cpassword: req.body.cpassword,
    fname: req.body.fname,
    lname: req.body.lname,
    gender: req.body.gender,
    date: req.body.date,
    email: req.body.email,
    tel: req.body.tel,
    gen: req.body.gen,
    year: req.body.year,
    
    image : req.file.path
   
   
  });
    await user.save()
    res.redirect('/users')
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่