Next.js Discord

Discord Forum

How to change a request body size limit in Next JS app router?

Unanswered
American Chinchilla posted this in #help-forum
Open in Discord
American ChinchillaOP
I created an API endpoint in Next JS app, using app router. It is a POST request that works as expected until the bigger body is sent.

The request is such that on different occasions it receives a different body. In some cases, body can contain one or many complex JSON objects that need to be analysed. When this is the case request responds with:

{"code":"413","message":"Request Entity Too Large"}

As a solution, I tried exporting a config object from route.ts file as below, but I cannot build my project as I get the message that it is deprecated.

export const config = {
api: {
bodyParser: {
sizeLimit: '8mb',
},
},
};

I looked online and was not able to find any solutions yet.

Any help would be highly appreciated.

0 Replies