FastifyError- Request body is too large

Fastify is a Node.Js Server Side Framework written on top of JavaScript scripting language. It has by default 1MB of Request Payload size limit. Passing a large payload or even more than 1MB of payload gives Request Body is too large error. Let’s resolve the FastifyError- Request body is too large error.

Below screenshot shows the default maximum payload size limit Fastify is allowed to accept.

Source: Fastify default Body Limit

How the error looks

Following screen shows the Fastify Request body too large error.

FST_ERR_CTP_BODY_TOO_LARGE- Request body is too large
FST_ERR_CTP_BODY_TOO_LARGE- Request body is too large

Resolve FastifyError- Request body is too large

To resolve the Request body too large error, we need to increase the default size in Fastify Server instance.

Provide the bodyLimit parameter in the Fastify create server options object.

Provide the size in bytes (convert to MB by multiplying 1024 twice) to bodyLimit parameter. Following line sets the default size limit to 30MB.

Save the changes and run application. Now you can send up-to 30MB of request body without any failure.

Conclusion

Fastify is Node.Js Framework to write Server-Side apps built on top of JavaScript platform. It is recommended to use with Node.Js TypeScript project.

The article resolves a very common fastify error ie. request body is too large error. Hope it helps you resolve your issue. If you still face the problem, make sure to comment below and we will try to look into the issue.

Checkout other JavaScript articles here.

Leave a Reply

Your email address will not be published. Required fields are marked *