简体   繁体   English

Express 4 FormData多部分解析POST请求

[英]Express 4 FormData multipart parse POST request

I'm trying to save incoming file from FormData xhr request but i can't even parse incoming request. 我正在尝试保存来自FormData xhr请求的传入文件,但我什至无法解析传入请求。 This is how i'm trying to send file: 这就是我试图发送文件的方式:

...
var formData = new FormData();
formData.append(fileType + '-blob', blob);
var request = new XMLHttpRequest();
request.open('POST', url);
request.send(data);
...

And this is how i'm trying to catch it: 这就是我想要抓住的方式:

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);
    });
});

I'm also using bodyParser in my app: 我还在我的应用程序中使用bodyParser:

var bodyParser = require('body-parser');
...
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
...

But when i'm trying to receive it, i'm getting raw data like: 但是,当我尝试接收它时,我得到的原始数据如下:

------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--

How can i parse it? 我该如何解析? When i send json data it works well. 当我发送json数据时,效果很好。

The body-parser module currently does not a provide a multipart/form-data parser. body-parser模块当前不提供multipart/form-data解析器。 For that you will need something like multer , busboy / connect-busboy , multiparty , or formidable . 对于您将需要像multerbusboy / connect-busboymultipartyformidable

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM