title: Cannot read property 'path' of undefined node js multer
body: <p>i am building a app that lets the user create a camp and than edit it.Recently i added the upload image feature it works fine with the create route but on the edit one it doesnt let the user leave it blank cause if that happens it give the undefined error.Do you have anyideas how i can fix this.I dont have much experience so any help would be welcomed.</p>
  
  <p>This is the js code </p>
  
  <pre><code>var express = require("express");
  var router = express.Router({mergeParams:true});
  var Campground = require("../models/campground");
  var middleware=require("../middleware");
  const multer = require('multer');
  
  
  const storage = multer.diskStorage({
      destination: function(req, file, cb) {
          cb(null, './uploads/');
      },
      filename: function(req, file, cb) {
          const now = new Date().toISOString(); const date = now.replace(/:/g, '-'); cb(null, date + file.originalname);
      }
  });
  
    const fileFilter = (req, file, cb) =&gt; {
      // reject a file
      if (file.mimetype === 'image/jpeg' || file.mimetype === 'image/png') {
        cb(null, true);
      } else {
        cb(null, false);
      }
    };
  
    const upload = multer({
      storage: storage,
      limits: {
        fileSize: 1024 * 1024 * 5
      },
      fileFilter: fileFilter
    });
  //edit
  router.get("/:id/edit",middleware.checkCampgroundOwnership, function(req,res){
  
  
              Campground.findById(req.params.id,function(err,foundCampground){
  
  
  
                        res.render("campgrounds/edit",{campground :foundCampground});
  
  
                });
  
  
  
  });
  
  router.put("/:id",upload.single('image'),middleware.checkCampgroundOwnership, function(req,res){
      var name = req.body.name;
      var image = req.file.path;
      var description = req.body.description;
      var price = req.body.price
  
      var upCampground = {price:price,name:name, image: image ,description:description};
      Campground.findByIdAndUpdate(req.params.id,upCampground,function(err,updatedCamp){
          if(err){
              res.redirect("/campgrounds");
          }
          else{
              res.redirect("/campgrounds/"+req.params.id);
          }
      })
  }); 
  </code></pre>
  
  <p>This is the ejs one</p>
  
  <pre><code>&lt;%-include ('../partials/header') %&gt;
  &lt;div class="container"&gt;
  
      &lt;h1 style="text-align: center;"&gt; Edit a &lt;%= campground.name%&gt;&lt;/h1&gt;
      &lt;div style="width: 30%; margin: 25px auto;"&gt;
          &lt;form action="/campgrounds/&lt;%=campground._id%&gt;?_method=PUT" enctype="multipart/form-data" method="POST"&gt;
              &lt;div class="form-group"&gt;
              &lt;input class="form-control" type="text" name="name" value="&lt;%= campground.name%&gt;"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;input class="form-control" type="number" name="price" value="&lt;%= campground.price%&gt; min="0.01" step="0.01""&gt;
                  &lt;/div&gt;
              &lt;div class="form-group"&gt;
              &lt;input class="form-control" type="file" name="image" value="\&lt;%= campground.image%&gt;"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;input class="form-control" type="text" name="description" value="&lt;%= campground.description %&gt;"&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
              &lt;button class="btn btn-primary btn-large btn-block"&gt;Submit&lt;/button&gt;
          &lt;/div&gt;
          &lt;/form&gt;
          &lt;a href="/campgrounds"&gt;Go back&lt;/a&gt;
          &lt;/div&gt;
  
  
  
  &lt;/div&gt;
  &lt;%-include ('../partials/footer') %&gt; 
  </code></pre>