title: Flutter :- Getting the "PayloadTooLargeError: request entity too large" error in "MultipartRequest" API?
body: <p><br>
  I am using the <code>MultipartRequest</code> for the image upload with the requested parameters, but getting the following exception from my below lines of code. The same API I have used the <code>Android Native</code> and its working very fine there, but  getting exception in Flutter Android platform, please check the below error I am getting from the server</p>
  
  <blockquote>
    <p><h1>request entity too large</h1><h2>413</h2><pre>PayloadTooLargeError: request entity too large
      at readStream (/data/consagous/loyaltie/node_modules/raw-body/index.js:155:17)
      at getRawBody (/data/consagous/loyaltie/node_modules/raw-body/index.js:108:12)
      at read (/data/consagous/loyaltie/node_modules/body-parser/lib/read.js:77:3)
      at jsonParser (/data/consagous/loyaltie/node_modules/body-parser/lib/types/json.js:135:5)
      at Layer.handle [as handle_request] (/data/consagous/loyaltie/node_modules/express/lib/router/layer.js:95:5)
      at trim_prefix (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:317:13)
      at /data/consagous/loyaltie/node_modules/express/lib/router/index.js:284:7
      at Function.process_params (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:335:12)
      at next (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:275:10)
      at logger (/data/consagous/loyaltie/node_modules/morgan/index.js:144:5)
      at Layer.handle [as handle_request] (/data/consagous/loyaltie/node_modules/express/lib/router/layer.js:95:5)
      at trim_prefix (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:317:13)
      at /data/consagous/loyaltie/node_modules/express/lib/router/index.js:284:7
      at Function.process_params (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:335:12)
      at next (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:275:10)
      at expressInit (/data/consagous/loyaltie/node_modules/express/lib/middleware/init.js:40:5)
      at Layer.handle [as handle_request] (/data/consagous/loyaltie/node_modules/express/lib/router/layer.js:95:5)
      at trim_prefix (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:317:13)
      at /data/consagous/loyaltie/node_modules/express/lib/router/index.js:284:7
      at Function.process_params (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:335:12)
      at next (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:275:10)
      at query (/data/consagous/loyaltie/node_modules/express/lib/middleware/query.js:45:5)
      at Layer.handle [as handle_request] (/data/consagous/loyaltie/node_modules/express/lib/router/layer.js:95:5)
      at trim_prefix (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:317:13)
      at /data/consagous/loyaltie/node_modules/express/lib/router/index.js:284:7
      at Function.process_params (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:335:12)
      at next (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:275:10)
      at Function.handle (/data/consagous/loyaltie/node_modules/express/lib/router/index.js:174:3)</pre></p>
  </blockquote>
  
  <p>I have used the below lines of code for the uploading the image using the Multipart like below, please check it once.</p>
  
  <pre><code>Future&lt;dynamic&gt; apiUploadImage(
        String url,
        String eventType,
        String name,
        String email,
        String password,
        String mobile,
        String _countryId,
        String _stateId,
        String _cityId,
        String _zipCId,
        String address,
        var lati,
        var longi,
        String _categoryId,
        File imageFile) async {
      print("Current state = " + _stateId + " " + _cityId);
  
      Uri uri = Uri.parse(url);
      MultipartRequest request = new MultipartRequest('POST', uri);
      request.headers[HEADER_CONTENT_TYPE_KEY] = HEADER_CONTENT_TYPE_VALUE;
      request.headers[HEADER_VERSION_KEY] = HEADER_VERSION_VALUE;
      request.headers[HEADER_DEVICE_TYPE_KEY] = HEADER_DEVICE_TYPE_VALUE;
      request.headers[HEADER_DEVICE_ID_KEY] = HEADER_DEVICE_ID_VALUE;
      request.headers[HEADER_AUTH_TOKEN_KEY] = HEADER_AUTH_TOKEN_VALUE;
      request.headers[HEADER_TIME_KEY] = HEADER_TIME_VALUE;
  
      request.fields['email'] = email;
      request.fields['password'] = password;
      request.fields['name'] = name;
      request.fields['mobile'] = mobile;
      request.fields['country'] = _countryId;
      request.fields['state'] = _stateId;
      request.fields['city'] = _cityId;
      request.fields['zip_code'] = _zipCId;
      request.fields['role_id'] = '3';
      request.fields['device_type'] = HEADER_DEVICE_TYPE_VALUE;
      request.fields['device_token'] = HEADER_AUTH_TOKEN_VALUE;
      request.fields['category_id'] = _categoryId;
      request.fields['address'] = address;
      request.fields['lati'] = lati.toString();
      request.fields['longi'] = longi.toString();
  
      print("Current state = " + _stateId + " " + _cityId);
  
      var stream =
          new http.ByteStream(DelegatingStream.typed(imageFile.openRead()));
      var length = await imageFile.length();
      var multipartFile = new MultipartFile("imagefile", stream, length,
          filename: imageFile.path);
      request.files.add(multipartFile);
  
      var response = await request.send();
  
      final respStr = await response.stream.bytesToString();
  
      debugPrint(respStr);
  
    }
  </code></pre>
  
  <p>Even though i even compressed the image file before sending but the problem is same, please check my compressor code for the image like below.</p>
  
  <pre><code>imageFile = await ImagePicker.pickImage(source: ImageSource.camera,imageQuality: 85);
  </code></pre>
  
  <p>I have searched the solutions , but it even not working please check it once.</p>
  
  <p><a href="https://stackoverflow.com/questions/19917401/error-request-entity-too-large/19965089#19965089">1). First link</a><br>
  <a href="https://stackoverflow.com/questions/50304779/payloadtoolargeerror-request-entity-too-large/55012934#55012934">2). Second link</a><br>
  <a href="https://stackoverflow.com/questions/36485333/node-js-request-entity-too-large-with-multer-upload">3). Third link</a><br>
  <a href="https://stackoverflow.com/questions/52016659/nodejs-router-payload-too-large">4). Forth link</a><br></p>
  
  <p>From the server-side , we have also increased the payload limit in node server like below, but it is not working</p>
  
  <pre><code>bodyParser = { json: {limit: '50mb', extended: true}, urlencoded: {limit: '50mb', extended: true} };
  </code></pre>
  
  <p>I have tried all the ways on server-side and my side and i have referred this link but all are not working for me.Please check the my above code and let me know where am i wrong? Thanks</p>