【发布时间】:2018-02-27 21:50:57
【问题描述】:
我使用expressjs通过POST上传大型arraybuffer,内容类型为application/octet-stream。
我使用中间件来读取这样的正文内容:
const getRawBody = require('raw-body');
/**
* Read body have content type is application/octet-stream
*/
app.use(function (req, res, next) {
if (req.headers['content-type'] === 'application/octet-stream') {
// using rawbody to read arrray buffer
getRawBody(req, {
length: req.headers['content-length'],
encoding: this.charset
}, function (err, string) {
if (err)
return next(err)
req.body = string
next()
})
}
else {
next()
}
});
当arraybuffer 有大文件(> 50MB)时。无法读取正文并向客户端返回错误(Chrome 崩溃,firefox xhr 返回错误)。
我不知道为什么。请帮我解决这个问题。 非常感谢
【问题讨论】:
-
您可能会窒息/内存不足导致 Chrome 崩溃。您需要将数据流式传输,而不是将其完全读入内存。