5

What is causing the PayloadTooLargeError error? I get it sometimes and also when the payload is a few KB (as far as I can figure out).

PayloadTooLargeError: request entity too large
    at readStream (/usr/local/lib/node_modules/expo-cli/node_modules/@expo/dev-server/node_modules/raw-body/index.js:155:17)
    at getRawBody (/usr/local/lib/node_modules/expo-cli/node_modules/@expo/dev-server/node_modules/raw-body/index.js:108:12)
    at read (/usr/local/lib/node_modules/expo-cli/node_modules/@expo/dev-server/node_modules/body-parser/lib/read.js:77:3)
    at jsonParser (/usr/local/lib/node_modules/expo-cli/node_modules/@expo/dev-server/node_modules/body-parser/lib/types/json.js:135:5)
    at call (/usr/local/lib/node_modules/expo-cli/node_modules/connect/index.js:239:7)
    at next (/usr/local/lib/node_modules/expo-cli/node_modules/connect/index.js:183:5)
    at serveStatic (/usr/local/lib/node_modules/expo-cli/node_modules/serve-static/index.js:75:16)
    at call (/usr/local/lib/node_modules/expo-cli/node_modules/connect/index.js:239:7)
    at next (/usr/local/lib/node_modules/expo-cli/node_modules/connect/index.js:183:5)

I found some solutions that you can set the limit to a higher value, but that's not specifically for Expo.io

There is no console.log used in the app

user1469734
  • 851
  • 14
  • 50
  • 81

3 Answers3

0

The error you are seeing could be caused by one of the packages you are using which uses body parser.

In body parser there is an option to limit to request body size:

limit
Controls the maximum request body size. If this is a number, then the value specifies the number of bytes; if it is a string, the value is passed to the bytes library for parsing. Defaults to '100kb'.

Taken from here.

You can see a related SO questions here and here.

I also saw this GitHub issue for Expo-Cli

tomerpacific
  • 4,704
  • 13
  • 34
  • 52
0

I had the same problem, after a lot of trials, I figure it out. The issue is related to the way you fetch the data, you are continuously fetching the data from database, which cause this error.

The solution is to fetch the data only once,

useEffect(() => {


  }, []);

Here is code example to

useEffect(() => {

const fetchUser = async () => {
  try {
    let user = await AsyncStorage.getItem('user_id');

    let parsed = JSON.parse(user);

    setUserId(parsed);

    //Service to get the data from the server to render
    fetch('http://myIpAddress/insaf/mobileConnection/ClientDashboard/PrivateReplyConsulationTab.php?ID=' + parsed)
    //Sending the currect offset with get request
    .then((response) => response.json())
    .then((responseJson) => {
      //Successful response from the API Call
      setOffset(offset + 1);
      const pri = Object.values(responseJson[0].reply_list);

      setPrivateReplies(pri);

      setLoading(false);

    })
    .catch((error) => {
      console.error(error);
    });
  }
  catch (error) {
    alert(error + "Unkbown user name")
  }
    }
    fetchUser();
  }, []);
Lama
  • 57
  • 8
-4

I think the storage is merging the old requests, so can you reset the async storage

AsyncStorage.clear()
Sreeram Nair
  • 2,369
  • 12
  • 27