title: Filter files on the basis of extension using Multer in Express JS
body: <p>As question title explains, I need to filter uploaded files on the basis of file extension. So, I went through the official docs and searched this website. </p>
  
  <p><strong>What I've Tried</strong></p>
  
  <p>I've tried solutions I came across. Files are being successfully uploaded, but the problem is how to filter files. Currently my Router.js file looks like this.</p>
  
  <p><strong><em>Router.JS</em></strong></p>
  
  <pre><code>var multer  = require('multer');
  var storage = multer.diskStorage({ //multers disk storage settings
      destination: function (req, file, cb) {
          cb(null, './public/uploads/')
      },
      limits:{
          files: 1,
          fileSize: 1024 * 1024
      },
      filename: function (req, file, cb) {
          var datetimestamp = Date.now();
          cb(null, file.fieldname + '-' + datetimestamp + '.' + file.originalname.split('.')[file.originalname.split('.').length -1])
      },
      onFileUploadStart: function(file) {
          console.log("Inside uploads");
          if (file.mimetype == 'image/jpg' || file.mimetype == 'image/jpeg' || file.mimetype == 'image/png') {
              return true;
          }
          else
          {
              return false;
          }
      }
  });
  var upload = multer({ //multer settings
      storage: storage
  }).single('profilepic');
  
  
  router.post('/profile', function(req, res){
      upload(req,res,function(err){
          if(err)
          {
              console.log(err);
          }
          else
          {
              console.log("Image was uploaded");
          }
      });
  });
  </code></pre>
  
  <p>I tried echoing something in <code>onFileUploadStart</code> to check if it is going into that function or not. And it was not. Besides <code>onFileUploadStart</code>, I also tried <code>fileFilter</code> as mentioned at this <a href="https://github.com/expressjs/multer/issues/114" rel="noreferrer">link</a>, but it was not helpful. Any suggestions how to solve this? Thanks in advance.</p>