title: How to get the body before uploading file in multer?
body: <p>In my project the admins have the ability to upload MP3 files and submit parameters to it like song name.</p>
  <p>I decided using <a href="https://github.com/expressjs/multer" rel="nofollow noreferrer">multer middleware</a> for handling <code>multipart/form-data</code>.</p>
  <p>My problem is <code>req.body.gender</code> returns always undefined, because I have to use it inside the <code>uploadSong</code> listener. I want to upload the song when the gender is zero.</p>
  <p><em>index.ejs</em></p>
  <pre><code>&lt;form method=&quot;post&quot; action=&quot;/acp&quot; role=&quot;publish&quot; enctype=&quot;multipart/form-data&quot;&gt;
      &lt;div class=&quot;form-group&quot;&gt;
          &lt;input type=&quot;file&quot; name=&quot;song&quot; id=&quot;song&quot; accept=&quot;audio/mpeg&quot;&gt;
      &lt;/div&gt;
  
      &lt;input type=&quot;checkbox&quot; name=&quot;gender&quot; checked data-toggle=&quot;toggle&quot; data-on=&quot;Male&quot; data-off=&quot;Female&quot;&gt;
  &lt;/form&gt;
  </code></pre>
  <p><em>app.js</em></p>
  <pre><code>var uploadSong = upload.single('song');
  app.post('/acp', isLoggedIn, function (req, res) {
  
      console.log(req.body.gender); // returns &quot;undefined&quot;
  
      if(req.body.gender == 0) { // returns &quot;undefined&quot;
  
          uploadSong(req, res, function (err) {
              if (err) {
                  res.send('uploaded');
                  return;
              }
              res.redirect('/');
  
          });
      
      }
  });
  </code></pre>