3

我正在使用多方。它工作正常,但突然抛出错误。

错误

err: { Error: stream ended unexpectedly
    at Form.<anonymous> (/user_code/node_modules/multiparty/index.js:754:24)
    at emitNone (events.js:91:20)
    at Form.emit (events.js:185:7)
    at finishMaybe (_stream_writable.js:514:14)
    at endWritable (_stream_writable.js:524:3)
    at Form.Writable.end (_stream_writable.js:489:5)
    at onend (_stream_readable.js:511:10)
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickDomainCallback (internal/process/next_tick.js:128:9) status: 400, statusCode: 400 }

代码

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

var multiparty = require('multiparty');
var http = require('http');
var util = require('util');

exports.helloWorld = functions.https.onRequest((request, response) => {
                                               var body = "";
                                               var POST = {};
                                               var form = new multiparty.Form();
                                               form.on('error', function(err) {
                                                       console.log('Error parsing form: ' + err.stack);
                                                       });
                                               form.parse(request, function(err, fields, files) {
                                                          response.status(500).send({
                                                                                    message: err
                                                                                    });
                                                          })
                                               });
});
4

1 回答 1

3

流意外结束”错误意味着底层 TCP 套接字在收到完整的多部分表单之前已关闭。

正如您所说,这以前是有效的,您应该检查您正在向其发出请求的服务器是否存在任何错误,这些错误可能会提前关闭响应。一个常见原因是响应数据的大小大于服务器或请求/响应标头所接受的大小。

于 2017-12-19T17:11:12.223 回答