Monday 15 July 2013

javascript - MEANJS : 413 (Request Entity Too Large) -



javascript - MEANJS : 413 (Request Entity Too Large) -

i using meanjs stack, upload image using ng-flow , save imgsrc base64 url.

data:image/png;base64,ivborw0kggoaaaansuheugaaarkaaaczcayaaac94ggra....

here mongoose schema:

var serviceschema = new mongoose.schema({ name : string, url: string, description : string, category : string, imgsrc: string });

i run request entity large server error big images.

i resize image prior upload still allows me image of size 200 x 200

$scope.resizeimageforupload = function(img){ var canvas = document.getelementbyid('canvas'); var max_width = 200; //400; big still var max_height = 200; //300 big still var width = img.width; var height = img.height; if (width > height) { if (width > max_width) { height *= max_width / width; width = max_width; } } else { if (height > max_height) { width *= max_height / height; height = max_height; } } canvas.width = width; canvas.height = height; var ctx = canvas.getcontext("2d"); ctx.drawimage(img, 0, 0, width, height); var dataurl = canvas.todataurl("image/png"); dataurl.replace(/^data:image\/(png|jpg);base64,/, ""); homecoming dataurl; };

any ideas on work around or alternate solution ?

request entity large: 413 error: request entity big @ makeerror (angular\expresstest\node_modules\body-parser\node_modules\raw-body\index.js:184:15) @ module.exports (angular\expresstest\node_modules\body-parser\node_modules\raw-body\index.js:40:15) @ read (angular\expresstest\node_modules\body-parser\lib\read.js:62:3) @ jsonparser (angular\expresstest\node_modules\body-parser\lib\types\json.js:87:5) @ layer.handle [as handle_request] (angular\expresstest\node_modules\express\lib\router\layer.js:76:5) @ trim_prefix (angular\expresstest\node_modules\express\lib\router\index.js:270:13) @ angular\expresstest\node_modules\express\lib\router\index.js:237:9 @ function.proto.process_params (angular\expresstest\node_modules\express\lib\router\index.js:312:12) @ angular\expresstest\node_modules\express\lib\router\index.js:228:12 @ function.match_layer (angular\expresstest\node_modules\express\lib\router\index.js:295:3)

you can add together next express config:

app.use(bodyparser.urlencoded({limit: '50mb'})); app.use(bodyparser.json({limit: '50mb'}));

basically need configure express webserver take bigger request size. replace 50mb whatever maxsize want accept.

hope helps!!!

javascript angularjs mongodb mongoose mean-stack

No comments:

Post a Comment