node.jsv4l2loopback

How to increase default maximum request body size in loopback 4 framework?


How to increase default maximum request body size in loopback 4 framework? I understand express is used internally by loopback 4, what I need to do is the equivalent of setting the limit param for the body-parser expressjs middleware.

Any ideas?

Thanks


Solution

  • server.bind(RestBindings.REQUEST_BODY_PARSER_OPTIONS).to({
      limit: '4MB',
    });
    

    or

    server.bind(RestBindings.REQUEST_BODY_PARSER_OPTIONS).to({
      json: {limit: '4MB'},
      text: {limit: '1MB'},
    });
    

    The list of options can be found in the body-parser module.

    By default, the limit is 1MB. Any request with a body length exceeding the limit will be rejected with http status code 413 (request entity too large).