MEANJS:413(请求实体过大) [英] MEANJS : 413 (Request Entity Too Large)

查看:259
本文介绍了MEANJS:413(请求实体过大)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是MEANJS栈,我使用 NG流上传图片并保存imgsrc为base64网址。

数据:图像/ PNG; BASE64,iVBORw0KGgoAAAANSUhEUgAAARkAAACzCAYAAAC94GgrA ....

下面是我的猫鼬的模式:

  VAR ServiceSchema =新mongoose.Schema({
    名称:字符串,
    网址:字符串,
    描述:字符串,
    类别:字符串,
    imgsrc:字符串
});

我为大图像碰上了请求实体过大服务器错误。

我可以调整在上传之前的形象,但是这仍然只允许我大小的图像200×200

  $ scope.resizeimageforupload =功能(IMG){
        VAR帆布=的document.getElementById('画布');        VAR MAX_WIDTH = 200; // 400;过大仍然
        VAR MAX_HEIGHT = 200; // 300过大仍然
        VAR WIDTH = img.width;
        VAR HEIGHT = img.height;        如果(宽>高度){
          如果(宽> MAX_WIDTH){
            高* = MAX_WIDTH /宽度;
            宽度= MAX_WIDTH;
          }
        }其他{
          如果(高度> MAX_HEIGHT){
            宽* = MAX_HEIGHT /高度;
            高度= MAX_HEIGHT;
          }
        }
        canvas.width =宽度;
        canvas.height =高度;
        变种CTX = canvas.getContext(2D);
        ctx.drawImage(IMG,0,0,宽度,高度);        VAR dataURL = canvas.toDataURL(图像/ PNG);
        dataURL.replace(/ ^数据:影像\\ /(PNG | JPG)的base64,/,);        返回dataURL;
    };

周围或替代的解决方案上的工作任何想法?

请求实体太大:413

错误:请求实体太大
    在makeError(角\\ EX presstest \\ node_modules \\体的解析器\\ node_modules \\原体\\ index.js:184:15)
    在module.exports(角\\ EX presstest \\ node_modules \\体的解析器\\ node_modules \\原体\\ index.js:40:15)
    在读(角\\ EX presstest \\ node_modules \\体的解析器\\ lib目录\\ read.js:62:3)
    在jsonParser(角\\ EX presstest \\ node_modules \\体的解析器\\ lib目录\\型号\\ json.js:87:5)
    在Layer.handle [如handle_request(角\\ EX presstest \\ node_modules \\ EX preSS \\ lib目录\\路由器\\ layer.js:76:5)
    在trim_ preFIX(角\\ EX presstest \\ node_modules \\ EX preSS \\ lib目录\\路由器\\ index.js:270:13)
    在角\\ EX presstest \\ node_modules \\ EX preSS \\ lib目录\\路由器\\ index.js:237:9
    在Function.proto.process_params(角\\ EX presstest \\ node_modules \\ EX preSS \\ lib目录\\路由器\\ index.js:312:12)
    在角\\ EX presstest \\ node_modules \\ EX preSS \\ lib目录\\路由器\\ index.js:228:12
    在Function.match_layer(角\\ EX presstest \\ node_modules \\ EX preSS \\ lib目录\\路由器\\ index.js:295:3)


解决方案

您可以添加以下内容前preSS配置:

  app.use(bodyParser.urlen codeD({限制:'50MB'}));
app.use(bodyParser.json({限制:'50MB'}));

基本上你需要配置防爆preSS Web服务器接受请求,大大小。你要接受任何MAXSIZE替换 50MB

希望这有助于!

I am using a MEANJS stack, I upload an image using ng-flow and save the imgsrc as base64 url.

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

Here is my mongoose schema:

var ServiceSchema = new  mongoose.Schema({
    name : String,
    url: String,
    description : String,
    category : String,
    imgsrc: String
});

I run into a Request Entity Too Large server error for large images.

I could resize the image prior to upload but this still only allows me image of size 200 x 200

$scope.resizeimageforupload = function(img){
        var canvas = document.getElementById('canvas');

        var MAX_WIDTH = 200; //400; too big still
        var MAX_HEIGHT = 200; //300 too 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,/, "");

        return dataURL;
    };

Any ideas on a work around or alternate solution ?

request entity too large: 413

Error: request entity too large
    at makeError (Angular\expresstest\node_modules\body-parser\node_modules\raw-body\index.js:184:15)
    at module.exports (Angular\expresstest\node_modules\body-parser\node_modules\raw-body\index.js:40:15)
    at read (Angular\expresstest\node_modules\body-parser\lib\read.js:62:3)
    at jsonParser (Angular\expresstest\node_modules\body-parser\lib\types\json.js:87:5)
    at Layer.handle [as handle_request] (Angular\expresstest\node_modules\express\lib\router\layer.js:76:5)
    at trim_prefix (Angular\expresstest\node_modules\express\lib\router\index.js:270:13)
    at Angular\expresstest\node_modules\express\lib\router\index.js:237:9
    at Function.proto.process_params (Angular\expresstest\node_modules\express\lib\router\index.js:312:12)
    at Angular\expresstest\node_modules\express\lib\router\index.js:228:12
    at Function.match_layer (Angular\expresstest\node_modules\express\lib\router\index.js:295:3)

解决方案

You can add following to express config:

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

Basically you need to configure Express webserver to accept bigger request size. Replace 50mb with whatever maxsize you want to accept.

Hope this helps!!!

这篇关于MEANJS:413(请求实体过大)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆