title: TypeError: Cannot read property 'filename' of undefined--multer
body: <p>I am currently facing a similar problem to this <a href="https://stackoverflow.com/questions/59526207/how-do-i-produce-multer-error-message-in-my-postman">post</a>. I managed to resolve my initial issue after referencing solutions posted there. However, when i tried to post a image that is less than 1MB and is a jpg formatted image( which i managed to do before the editing), it now fails and state that <code>TypeError: Cannot read property 'filename' of undefined</code>.</p>
  <p>My app.js code:</p>
  <pre><code>const upload = multer({
      dest: storage,
      storage: storage,
      limits: {
        fileSize: 1024 * 1024
      },
      fileFilter: function(req, file, callback,error) {
          var ext = path.extname(file.originalname);
          var error_msg = error instanceof multer.MulterError;
          if(ext !== '.jpg') {
               req.fileValidationError = &quot;Not a jpg file!&quot;;
               return callback(null, false, req.fileValidationError);
          }
          if(error_msg) {
              req.fileSizeError = &quot;Image more than&quot;
              return callback(null, false, req.fileSizeError)
          }
          callback(null,true)
      }
    });
  
  app.post(&quot;/upload&quot;, function (req, res, next) {
      upload.single('name')(req, res, function (error) {
          if(req.fileValidationError) {
              res.status(500).send({message:req.fileValidationError});
          }
          else {
              if(error.code === 'LIMIT_FILE_SIZE') {
                  req.fileSizeError = &quot;Image more than 1MB!&quot;;
                  res.status(500).send({message:req.fileSizeError});
              }
              else {
                  console.log('File Received!');
                  console.log(req.file);
                  var sql = &quot;INSERT INTO `file`(name,description,type,size) VALUES('&quot; + req.file.filename + &quot;', '&quot; + (req.file.encoding + &quot;_&quot; + req.file.destination + &quot;_&quot; + req.file.path)+ &quot;', '&quot; + req.file.mimetype + &quot;', '&quot; + req.file.size + &quot;')&quot;;
                  db.query(sql, (error, results) =&gt; {
                      console.log('Inserted Data!');
                  });
              const message = &quot;Successfully Uploaded!&quot;
              res.status(200).send({message:message, file_details:req.file})
              }
          }
      })
  })
  </code></pre>