本文介绍了解析表单数据Node.js Express的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在以这种形式获取表单数据
I am getting form data in this form
'------WebKitFormBoundarysw7YYuBGKjAewMhe\r\nContent-Disposition: form-data; name': '"a"\r\n\r\nb\r\n------WebKitFormBoundarysw7YYuBGKjAewMhe--\r\n
我正在尝试找到一种中间件,该中间件将允许我访问以下表单数据:
I'm trying to find a middleware that will allow me to access the form data like:
req.body.a // -> 'b'
我尝试过
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
我的实现是否存在问题,或者我没有使用正确的中间件?
Is there a problem with my implementation or am I not using the correct middleware?
推荐答案
有效的工具是 multiparty
app.post('/endpoint', function (req, res) {
var form = new multiparty.Form();
form.parse(req, function(err, fields, files) {
// fields fields fields
});
})
这篇关于解析表单数据Node.js Express的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!