title: How can i navigate user to same page when the errors occurs in multer upload nodejs
body: <p>I am doing some experiment over nodejs for my new project and doing it on Image upload. I am using Express MVC with mongodb. I want to send user back to same page with validation errors from multer configuration itself. There is no response parameter in <code>filename</code> function of multer.</p>
  
  <pre><code>var multer = require('multer');
  
  var storage = multer.diskStorage({
   destination: function (request, file, callback) {
      callback(null, 'public/uploads/');
   },
      filename: function (request, file, callback) {// Validations &amp; File Name can be set/changed here
      if (file.mimetype !== 'image/png' &amp;&amp; file.mimetype !== 'image/jpg' &amp;&amp; file.mimetype !== 'image/jpeg') {
          console.log('File extensions required are png, jpg, jpeg');
          return false;
      } else {
          var rString = randomString.generate({ length: 12, charset: 'alphabetic' });
          callback(null, rString + '_' + Date.now() + path.extname(file.originalname));
      }
  }
  });
  
  var upload = multer({ storage: storage }).single('displayImage');
  </code></pre>
  
  <p>My route is</p>
  
  <pre><code>router.route('/change-avatar')
  .get(function (req, res) {
      res.render('views/profile/changeAvatar');
  })
  .post(function (req, res) {
      var id = req.session.userId;
      upload(req, res, function (err) {
          if (err) { console.log(err); return; } // if error
          console.log(req.files);
          response.end('Your File Uploaded');
          console.log('Photo Uploaded');
      });
  });
  </code></pre>
  
  <p>How could it be done.</p>
  
  <p>Thanks</p>