Uploading a file and passing a additional parameter with multer
<p>I am using the <a href="https://github.com/malsup/form/" rel="noreferrer"><code>jQuery Form Plugin</code></a> and <a href="https://github.com/expressjs/multer" rel="noreferrer"><code>multer</code></a> to upload files to my server. This works just fine, but I am trying to pass an additional parameter, which will determine where exactly the file will be saved.</p>

<p>I have following code, which I would like to extend to behave as stated:</p>

<h1>HTML</h1>

<pre><code>&lt;form id="uploadForm"
      enctype="multipart/form-data"
      action="/files"
      method="post"&gt;
    &lt;input type="file" id="userFile" name="userFile"/&gt;
    &lt;input type="text" hidden id="savePath" name="savePath" value="path"/&gt;
&lt;/form&gt;
</code></pre>

<h1>Client JS</h1>

<pre><code>uploadForm.submit(function() {
    $(this).ajaxSubmit({

        error: function(xhr) {
            console.log('Error: ' + xhr.status);
        },

        success: function(response) {
            console.log('Success: ' + response);
        }
    });

    return false;
});
</code></pre>

<h1>Node.js Route</h1>

<pre><code>app.post(APIpath + "file",function(req,res){
    var storage = multer.diskStorage({
        destination: absoluteServePath+ "/" + config.filePath,
        filename: function (req, file, cb) {
            cb(null, file.originalname);
        }
    });
    var upload = multer({ storage : storage}).any();

    upload(req,res,function(err) {
        if(err) {
            console.log(err);
            return res.end("Error uploading file.");
        }
        res.end("File has been uploaded");
    });
});
</code></pre>

<p><strong>Note:</strong> I know I am not checking for mimetypes or sanitizing the user files, but it is mainly secondary for me right now.</p>