Situation
I'm using MEAN.JS framework (MongoDB, ExpressJS, AngularJS and NodeJS).
Using AngularJS in frontEnd; I have a JSON with a base64 encoded image in a field.
What I want?
- I want to send this JSON to the server (NodeJS).
I'm using RESTful:
controller:
var article = new Articles ($scope.article);
article.$save(function(response) {
//If all is OK
}, function(errorResponse) {
//Error
});
$scope.article
have a field named "image" ($scope.article.image) with the base64 string of the image.
service:
(function() {
'use strict';
angular
.module('articles')
.factory('articles', ['$resource',
function($resource) {
return $resource('articles/:articleId', { articleId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}
]);})();
Problems
If the JSON don't have any Base64 Image in a field works fine...
But...
If we add the Base64 String of the Image in a field the server response with this error:
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)
Say that the request entity is too large... The image size is 84Kb!!!!!
(I tried with $http resource and occurs the same...)
- How can I solve this server error?
- What is the best way to send from Angular to Node a Base64 encoded image?
- Any suggestions?
Relationed answers:
I tried to do this but don't work and don't understand:
app.use(bodyParser.urlencoded({limit: '50mb'}));
app.use(bodyParser.json({limit: '50mb'}));
bodyParser is deprecated and the size of the Base64 Image is 84kb!!!!!
Thank you!!