title: Multiple file uploads in nodejs using express-fileupload?
body: <p>Currently I am able to post this to mongodb. It works fine.</p>
  <p><strong>PROBLEM</strong>
  Instead of one attachment, I should be able to post many attachments independent of each other, there will be N different buttons available for the N uploads.</p>
  <pre><code>const form = (req, res, next) =&gt; {
  
    const file = req.files.photo;
  
    file.name = `photo_${Math.random(0, 10012)}-${Math.random(0, 2000)}${
      path.parse(file.name).ext
    }`;
  
    file.mv(`./public/uploads/${file.name}`, async (err) =&gt; {
      if (err) {
        console.error(err);
        return res.status(500).json({
          message: `Problem With File Upload`,
        });
      }
      
      const upload = await Form.create({
         approved: req.body.approved,
         email_: req.body.email,
  
         formData: {
          name: &quot;req.body.formData.claimantName&quot;,
          nationality: &quot;req.body.formData.claimantNationality&quot;,
          address: &quot;req.body.formData.claimantAddress&quot;,
          email: &quot;req.body.formData.claimantEmail&quot;,
        }, 
  
        fileOne: file.name1,
            
        // these are the next 
        // fileTwo: req.body.formData.name2,
        // fileThree: req.body.formData.name3,
  
      });
      return res.status(200).json({
        success: true,
        message: `File Uploaded Successfully`,
        path: file.name,
      });
    });
  };
  
  router.route(&quot;/add&quot;).post(form);
  
  </code></pre>
  <p>I tried moving <code>const upload = await Form.create(...)</code> outside the <code>file.mv(...)</code> block and do somthing like this```
  const file1 = req.files.photo1;</p>
  <p>file1.name = <code>photo_${Math.random(0, 10012)}-${Math.random(0, 2000)}${ path.parse(file1.name).ext }</code>;</p>
  <pre><code>It doesn't work properly.
  </code></pre>