title: Custom code parsing issue- Request Entity Too Large - Oracle MCS
body: <p>Hi I am facing an issue while accessing custom api using Oracle MCS</p>
  
  <pre><code>{
   "message": "Custom Code Problem parsing JSON: request entity too large"
  }
  </code></pre>
  
  <p>This occur while calling an api with request containing a byte array of an image. 
  my code given below</p>
  
  <pre><code>service.post('/mobile/custom/meraasmcs/documentofrecords/updateemiratesid',function(req,res){
              console.info("Request Before Api call=&gt;"+req);
              var connector = '/documentofrecords/updateemiratesid'
              commonHandler.CommonHandlerPostMethodFunction(
                      req,res,connector)
  </code></pre>
  
  <h2>commonHandler.js</h2>
  
  <pre><code>module.exports = {
   CommonHandlerPostMethodFunction: 
       function (req, res, connector) {
          /*
           * Description : This function handles all the request and response
           * Output :     Returns a json content success message
           * Author : Anand Raj
           * Created Date : 10/10/2016
           */
           var app = express();
           var newReqBody=app.use(bodyParser.json({limit: '50mb'}));
           console.info('New ReqBody=&gt;'+newReqBody);
          var errorMsg;
          var finalResponse;
          var headerIndex = JSON.stringify(
                  req.headers).search('application/json');
          var versionNumberIndex = JSON.stringify(
                  req.headers).search('x-api-version');
          var reqBody = JSON.stringify(req.body);
          console.info('header ' + JSON.stringify(req.headers));
          console.info('version index ' + versionNumberIndex);
          console.info('version number ' + req.headers['x-api-version']);
          console.info('Req body ' + reqBody);
          res.header('Access-Control-Allow-Origin','*');  // To overcome cross origin issue in Windows platform
          if (0 &gt; headerIndex) {
                  finalResponse = jbuilder.encode(function (json) {
                       json.set('Response', function (json) {
                            json.set('responseCode', '415');
                            json.set('responseMessage', 'Unsupported media-type');
                       });
  
                  });
              res.status(415).send(finalResponse);
              res.end();
          } else if (reqBody === '{}') {
              finalResponse = jbuilder.encode(function (json) {
                  json.set('Response', function (json) {
                    json.set('responseCode', '400');
                    json.set('responseMessage', 'Malformed request body');
                  });
  
              });
              res.status(400).send(finalResponse);
              res.end();
          } else if (0 &gt; versionNumberIndex) {
              finalResponse = jbuilder.encode(function (json) {
                   json.set('Response', function (json) {
                        json.set('responseCode', '400');
                        json.set('responseMessage', 'Version Number missing');
                   });
  
              });
              res.status(400).send(finalResponse);
              res.end();
          } else {
              /* request part */
              var versionNumber = req.headers['x-api-version'];
              var optionsList = {
                  uri: '/mobile/connector/MeraasAllConnector'+connector,
                  body: reqBody,
                  headers: {
                      'Content-Type': 'application/json',
                      'X-API-Version': versionNumber
                  }
              };
              /* handler part */
              var handler = function (error, response, body) {
                  if (error) {
                      if ('message' in error) {
                          errorMsg = error.message;
                          //res.send(500, errorMsg);
                          //res.end();
                          finalResponse = jbuilder.encode(function (json) {
                                  json.set('Response', function (json) {
                                      json.set('responseCode', '500');
                                      json.set('responseMessage', errorMsg);
                                  });
  
                          });
                          res.status(500).send(finalResponse);
                          res.end();
                      } else {
                          finalResponse = jbuilder.encode(function (json) {
                                  json.set('Response', function (json) {
                                      json.set('responseCode', '408');
                                      json.set('responseMessage', 'Response Timed Out');
                                  });
  
                          });
                          res.status(408).send(finalResponse);
                          res.end();
                      }
                  } else {
                      if (response.statusCode !== 200) {
                          finalResponse = jbuilder.encode(function (json) {
                                  json.set('Response', function (json) {
                                      json.set('responseCode', response.statusCode);
                                      json.set('responseMessage', response.message);
                                  });
  
                          });
                          res.status(response.statusCode).send(finalResponse);
                          res.end();
                      } else if(response.statusCode==401){
                          finalResponse = jbuilder.encode(function (json) {
                                  json.set('Response', function (json) {
                                      json.set('responseCode', '401');
                                      json.set('responseMessage', 'Authorization Required.');
                                  });
  
                          });
  
                           res.status(401).send(finalResponse);
                           res.end();
                      }
                      else {
                          res.status(200).send(body);
                          res.end();
                      }
                  }
              };
            req.oracleMobile.rest.post(optionsList, handler);
         }        
  }
  </code></pre>
  
  <p>};</p>
  
  <h2>Package.json</h2>
  
  <pre><code>    {
    "name" : "meraasmcs",
    "version" : "1.47.0",
    "description" : "Contains all the custom Apis for Meraas Mobile App",
    "main" : "meraasmcs.js",
    "dependencies":
      {
      "jbuilder":"0.0.4",
      "body-parser":"1.15.2",
      "express":"4.14.0"
      },
    "oracleMobile" : {
      "dependencies" : {
        "apis" : { },
        "connectors" : {"/mobile/connector/MeraasAllConnector":"1.0"}
      }
    }
  }
  </code></pre>
  
  <p>If i reduce the size of image then pass its corresponding byte array, then there response will be success. </p>
  
  <p>I checked related questions, all it says </p>
  
  <pre><code>var bodyParser = require('body-parser');
  app.use(bodyParser.json({limit: '50mb'}));
  app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
  </code></pre>
  
  <p>But i tried that also. Could anyone please help me??</p>
  
  <h2>Sample Request</h2>
  
  <pre><code>{
  "P_PERSON_ID": 31441,
  "P_LOGIN_PERSON_ID": 31441,
  "TIME_STAMP": null,
  "P_EMIRATES_ID_TAB": [{
      "DocumentExtraInfoId": "",
      "ValidFrom": "2016-11-23",
      "ValidTo": "2016-11-24",
      "CardNumber": "Ggv4"
  }],
  "P_ATTACHMENT_TAB": [{
      "Title": "image.jpg",
      "DocumentId": null,
      "DeleteFlag": "N",
      "Description": "Testqwe",
      "AttachmentName": "Test",
      "FileData": "",
      "AttachmentType": "image/jpeg"
  }]
  </code></pre>
  
  <p>}</p>
  
  <p>Issue comes when the length of the value of <strong>FileData</strong> is too large.</p>
  
  <p>Thanks in advance</p>