Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find data from multiple input fields on the server side (Express.js/Node.js)?
    primarykey
    data
    text
    <p>I have a form with multiple description text fields, file chose field and submit button for the Cross-Domain request (CORS variant):</p> <pre><code> &lt;form class="upload" id="upload_form" enctype="multipart/form-data" method="post" action="http://localhost:3001/upload/1234567890"&gt; &lt;div class="row-fluid"&gt; &lt;div class="span5 row-fluid" id="description" style="margin-left:0px;"&gt; &lt;div&gt; &lt;label&gt;Title&lt;/label&gt; &lt;input class="span12" type="text" placeholder="Title" id="description_title" name="description_title"/&gt; &lt;label&gt;Author&lt;/label&gt; &lt;input class="span12" type="text" placeholder="Author" id="description_author" name="description_author"/&gt; &lt;label&gt;Tags&lt;/label&gt; &lt;input class="span12" type="text" placeholder="Tags" id="description_tags" name="description_tags"/&gt; &lt;label&gt;Description&lt;/label&gt; &lt;textarea class="span12" id="description_textarea" name="description_textarea" rows="5" style="resize:none"&gt;&lt;/textarea&gt; &lt;div id="buttons" class="row-fluid" style="margin-top: 5px"&gt; &lt;div class="span12"&gt; &lt;span class="span5 btn btn-primary btn-file" id="chose_files_btn" onclick="filechose_button.click()"&gt;chose files &lt;input id="filechose_button" type="file" name="fileData" data-url="http://localhost:3001/upload/1234567890"/&gt;&lt;/span&gt; &lt;button id="upload_button" type="submit" name="upload" class="span5 offset2 btn btn-success" disabled="true" onclick="$('#upload_form').trigger('upload_fired');"&gt;upload&lt;/button&gt; &lt;/div&gt; &lt;!-- span12 --&gt; &lt;/div&gt; &lt;!-- buttons --&gt; &lt;/div&gt; &lt;!-- well --&gt; &lt;/div&gt; &lt;!-- video_description --&gt; &lt;/div&gt; &lt;!-- row-fluid --&gt; &lt;/form&gt; </code></pre> <p>The Node.js (Express.js) server has a route:</p> <pre><code>app.post('/upload/:id', function(req, res){ console.log(req.fields); ... }); </code></pre> <p>The problem is, I can not find the data from input fields: <code>req.fields</code> gets <strong><code>undefined</code></strong>.</p> <p>How can I find the data (text description and a file) from the <code>req</code> on the server?</p> <hr> <h2>Update:</h2> <p>Great! <code>req.body</code> really get access to all the fields, <strong>BUT:</strong></p> <pre><code>console.log(req.body) </code></pre> <p>prints:</p> <pre><code>{ description_title: 'aaa', description_author: 'bbb', description_tags: 'ccc', description_textarea: 'ddd', upload: '' } </code></pre> <p>but where is the <code>fileData</code> field? I mean, where the file I upload with the description (aforementioned fields)?</p> <h2>Update 2: Done!</h2> <p>Files are not in the body attribute, but in the <strong><code>req.files</code></strong></p> <p>Thanks for <strong>Adam</strong> and <strong>andyfan</strong>!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload