Express 4 FormData 多部分解析 POST 请求
Express 4 FormData multipart parse POST request
我正在尝试保存来自 FormData xhr 请求的传入文件,但我什至无法解析传入请求。这就是我尝试发送文件的方式:
...
var formData = new FormData();
formData.append(fileType + '-blob', blob);
var request = new XMLHttpRequest();
request.open('POST', url);
request.send(data);
...
这就是我试图抓住它的方式:
var express = require('express');
var router = express.Router();
router.post('/savestream', function(req, res) {
var body = '';
req.on('readable', function() {
body += req.read();
});
req.on('end', function() {
//body = JSON.parse(body);
console.log(body);
res.end(body);
});
});
我也在我的应用程序中使用 bodyParser:
var bodyParser = require('body-parser');
...
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
...
但是当我尝试接收它时,我得到的原始数据如下:
------WebKitFormBoundaryB0wkHt33s0gbqiB3
Content-Disposition: form-data; name="video-blob"; filename="blob"
Content-Type: video/webm
Eߣ@ B��B��B��B�B�@webmB��B��S�g )I�f@(*ױ@B@M�@whammyWA@whammyD�@6T�k@3�@0ׁcŁ��"��@und�@V_VP8%��@VP8����@@���C�u@����@���P�*@�>m6�I�#"� (�in�wa@ ��l����9}�r�d�=���{퓐��'!��NC�l����9}�r�d�=���{퓐��'!��NC�l����9}�r�d�=���{퓐��'!��NC�l����9}�r�d�=���{퓐��'!��NC�l�����
------WebKitFormBoundaryB0wkHt33s0gbqiB3--
我该如何解析它?当我发送 json 数据时,它运行良好。
body-parser
模块目前不提供 multipart/form-data
解析器。为此,您需要 multer
、busboy
/connect-busboy
、multiparty
或 formidable
.
我正在尝试保存来自 FormData xhr 请求的传入文件,但我什至无法解析传入请求。这就是我尝试发送文件的方式:
...
var formData = new FormData();
formData.append(fileType + '-blob', blob);
var request = new XMLHttpRequest();
request.open('POST', url);
request.send(data);
...
这就是我试图抓住它的方式:
var express = require('express');
var router = express.Router();
router.post('/savestream', function(req, res) {
var body = '';
req.on('readable', function() {
body += req.read();
});
req.on('end', function() {
//body = JSON.parse(body);
console.log(body);
res.end(body);
});
});
我也在我的应用程序中使用 bodyParser:
var bodyParser = require('body-parser');
...
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
...
但是当我尝试接收它时,我得到的原始数据如下:
------WebKitFormBoundaryB0wkHt33s0gbqiB3
Content-Disposition: form-data; name="video-blob"; filename="blob"
Content-Type: video/webm
Eߣ@ B��B��B��B�B�@webmB��B��S�g )I�f@(*ױ@B@M�@whammyWA@whammyD�@6T�k@3�@0ׁcŁ��"��@und�@V_VP8%��@VP8����@@���C�u@����@���P�*@�>m6�I�#"� (�in�wa@ ��l����9}�r�d�=���{퓐��'!��NC�l����9}�r�d�=���{퓐��'!��NC�l����9}�r�d�=���{퓐��'!��NC�l����9}�r�d�=���{퓐��'!��NC�l�����
------WebKitFormBoundaryB0wkHt33s0gbqiB3--
我该如何解析它?当我发送 json 数据时,它运行良好。
body-parser
模块目前不提供 multipart/form-data
解析器。为此,您需要 multer
、busboy
/connect-busboy
、multiparty
或 formidable
.