Receive same Name inputs AND Multipart/form-data inputs simultaneously on NodeJS as an Array and FileAttachment
<p>I'm having some trouble with using the <strong>enctype</strong> <code>multipart/form-data</code> while at the same time sending inputs with the same name to be obtained as an array. I can only seem to obtain an uploaded image OR the array inputs, but not both at the same time...</p>

<p>For example, I have this form:</p>

<pre><code>&lt;form method="post" action="/test"&gt;
  &lt;input name="testinput" value="valueA"&gt;
  &lt;input name="testinput" value="valueB"&gt;
  &lt;input type="file" name="fileattachment"&gt;
  &lt;input type="submit" value="Submit"&gt;
&lt;/form&gt;
</code></pre>

<p>If I set the form's enctype to be <code>multipart/form-data</code>, like this:</p>

<pre><code>&lt;form method="post" action="/test" enctype="multipart/form-data"&gt;
</code></pre>

<p>I end up receiving the 'fileattachment' just fine in my NodeJS app, BUT i only get the last value for 'testinput', like this:</p>

<pre><code>//req.body
//---
{
    testinput: 'valueB' // I'm missing valueA!
}

//req.files
//---
{
    fileattachment: { 
        name: 'biglogo.png',
        data: &lt;Buffer 89 ... &gt;,
        encoding: '7bit',
        mimetype: 'image/png',
        mv: [Function] 
    }
}
</code></pre>

<p>If the enctype is not set, the 'testinput' data comes as an array, BUT the 'fileattachment' is lost and I only get the name of the uploaded file, like this:</p>

<pre><code>//req.body
//---
{
    testinput: ['valueA', 'valueB'],
    fileattachment: 'some_picture.png' // Useless for file uploading
}
</code></pre>

<p>I think it has something to do with the way I've set up express' body parser, but I can't seem to figure out the right configuration. This is my setup (simplified for the relevant code):</p>

<pre><code>var express = require('express');
var fileUpload = require('express-fileupload');
var bodyParser = require('body-parser');

var app = express();
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(fileUpload()); // Must be placed after, not before, bodyparser's use, otherwise files fail to be uploaded correctly...

app.post('/test', function(req, res) { 
    // Some code
});
</code></pre>

<p>Also, this is my package.json file:</p>

<pre><code>{
    "name": "my-app",
    ...
    "dependencies": {
        "body-parser": "~1.15",
        "express": "~4.14",
        "express-fileupload": "^0.0.5"
    }
}
</code></pre>

<p>This is running on <code>node/6.9.1</code></p>

<p>I've seen this very similar question <a href="https://stackoverflow.com/questions/23674208/multipart-form-data-with-arrays" title="Multipart/form-data with arrays">Multipart/form-data with arrays</a>, but it is 2 years old, unanswered and doesn't seem to use the dependency <code>fileUpload</code>.</p>

<p>Also, I tried the approach proposed by the answer to this question <a href="https://stackoverflow.com/questions/18649881/handling-input-arrays-in-express-forms" title="Handling input arrays in Express forms?">Handling input arrays in Express forms?</a>, but all I keep getting on the server looks is text instead of arrays, like this:</p>

<pre><code>{ 
    'something[0][testinput]': 'valueA',
    'something[1][testinput]': 'valueB'
}
</code></pre>

<p>What am I missing? What should I try?</p>