我有一个运行v0.10.33的节点应用程序,带有Restify模块^ 2.8.3
var app = restify.createServer();
app.use(restify.queryParser());
app.use(restify.bodyParser({
maxBodySize: 1, //TODO: This limit is not working at the moment.
uploadDir: './temp',
keepExtensions: true
}));
app.post('/users/profile/picture', function(req, res, next) {
res.end('Upload done!');
};
文件上传有效,但不尊重maxBodySize参数。其余的参数:keepExtensions,uploadDir等运行良好。
为什么忽略maxBodySize?
答案 0 :(得分:0)
因为你的contentType是multipart / form-data或octet-stream
在lib / plugins / body_reader.js
if ((req.getContentLength() === 0 && !req.isChunked()) ||
req.contentType() === 'multipart/form-data' ||
req.contentType() === 'application/octet-stream') {
next();
return;
}
var bodyWriter = createBodyWriter(req);
function done() {
if (maxBodySize && bytesReceived > maxBodySize) {
var msg = 'Request body size exceeds ' +
maxBodySize;
next(new RequestEntityTooLargeError(msg));
return;
}