我有一个 HTML 代码,它接受批处理名称(下拉列表)、参数(文本区域)、电子邮件 ID(测试)和批处理文件 .txt 输入文件(文件)。当我在前端表单中单击“提交”时,我在日志中看到以下内容:
GET /batch?batches=Batch1 - - ms - -
我不知道如何通过 NodeJS 脚本知道并提取文件名并将其存储在服务器端?另外,捕获用户提交的文本区域的方法是什么?
<form action="batch">
<label for="batch">Select Batch </label>
<select name="batches" id="batch">
<select name="batches" id="batch">
<option value="" disabled="disabled" selected="selected">Please select a batch</option>
<option value="1">Batch1</option>
<option value="2">Batch2</option>
<option value="3">Batch3</option>
<option value="4">Batch4</option>
<option value="5">Batch5</option>
</select>
</p>
<br/>
<p>
<label for="binpfile">Batch Input File</label>
<input type="file" id="binpfile" accept=".txt">
</p>
<br/>
<p>
<label for="emailid">E-Mail ID:</label>
<input type="text" id="emailid"><br>
</p>
<br/>
<p class="formfield">
<label for="bparam">Batch Parameters:</label>
<textarea rows="4" cols="50" id="bparam" form="usrform">Enter batch param here...</textarea>
<input type="submit" value="Submit">
</form>
下面是我的 NodeJS 代码:我在日志中看到“用户输入 Batch1 未定义未定义未定义”
exports.processbatch = function(req, resp) {
var bname = req.query['batches'];
var fname = req.query['binpfile'];
var emailid = req.query['emailid'];
var bparam = req.query['bparam'];
console.log ('User entered ' + bname + ' ' + fname + ' ' + emailid + ' ' + bparam);
};
最佳答案
为什么不检查“req.query”对象?
console.log(req);
关于node.js - 如何获取前端上传的文件并本地存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35200126/