我正在使用MEAN.JS框架(MongoDB,ExpressJS,AngularJS和NodeJS)。
在frontEnd中使用 AngularJS ;我在字段中有 JSON , base64 编码图片。
我正在使用 RESTful :
控制器 :
var article = new Articles ($scope.article);
article.$save(function(response) {
//If all is OK
}, function(errorResponse) {
//Error
});
$scope.article
有一个名为“图片”($ scope.article.image)的字段,其中包含图片的base64字符串。
服务:
(function() {
'use strict';
angular
.module('articles')
.factory('articles', ['$resource',
function($resource) {
return $resource('articles/:articleId', { articleId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}
]);})();
如果JSON在字段中没有任何Base64图像可以正常工作......
但是...
如果我们在字段中添加图像的Base64字符串,则服务器响应时出现错误:
Error: request entity too large at makeError (/Users/aralroca/Documents/Aral/Projecte/node_modules/body-parser/node_modules/raw-body/index.js:184:15)
at module.exports (/Users/aralroca/Documents/Aral/Projecte/node_modules/body-parser/node_modules/raw-body/index.js:40:15)
at read (/Users/aralroca/Documents/Aral/Projecte/node_modules/body-parser/lib/read.js:62:3)
at jsonParser (/Users/aralroca/Documents/Aral/Projecte/node_modules/body-parser/lib/types/json.js:96:5)
at Layer.handle [as handle_request] (/Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:269:13)
at /Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:236:9
at Function.proto.process_params (/Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:311:12)
at /Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:227:12
at Function.match_layer (/Users/aralroca/Documents/Aral/Projecte/node_modules/express/lib/router/index.js:294:3)
假设请求实体太大 ...图片大小 84Kb !!!!!
(我尝试使用$http resource并发生相同的事情......)
相关答案:
我试图这样做但是不起作用并且不明白:
app.use(bodyParser.urlencoded({limit: '50mb'}));
app.use(bodyParser.json({limit: '50mb'}));
不推荐使用bodyParser,Base64图片的大小为 84kb !!!!!
谢谢!!
答案 0 :(得分:0)
尝试使用:
var express = require('express');
var app = express();
var busboy = require('connect-busboy');
app.post("/url_path",
busboy({
limits: {
fileSize: 10 * 1024 * 1024
}
}),
function(req, res, next) {
// check that the request's body was as expected
if (!req.busboy) return next('route'); // or next(new Error('...'));
// ...
});
// ...
了解详情this private npm。