Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
119 lines
3.3 KiB
Plaintext
119 lines
3.3 KiB
Plaintext
---
|
|
title: proxyClientMaxBodySize
|
|
description: Configure the maximum request body size when using proxy.
|
|
version: experimental
|
|
---
|
|
|
|
When proxy is used, Next.js automatically clones the request body and buffers it in memory to enable multiple reads - both in proxy and the underlying route handler. To prevent excessive memory usage, this configuration option sets a size limit on the buffered body.
|
|
|
|
By default, the maximum body size is **10MB**. If a request body exceeds this limit, the body will only be buffered up to the limit, and a warning will be logged indicating which route exceeded the limit.
|
|
|
|
## Options
|
|
|
|
### String format (recommended)
|
|
|
|
Specify the size using a human-readable string format:
|
|
|
|
```ts filename="next.config.ts" switcher
|
|
import type { NextConfig } from 'next'
|
|
|
|
const nextConfig: NextConfig = {
|
|
experimental: {
|
|
proxyClientMaxBodySize: '1mb',
|
|
},
|
|
}
|
|
|
|
export default nextConfig
|
|
```
|
|
|
|
```js filename="next.config.js" switcher
|
|
/** @type {import('next').NextConfig} */
|
|
const nextConfig = {
|
|
experimental: {
|
|
proxyClientMaxBodySize: '1mb',
|
|
},
|
|
}
|
|
|
|
module.exports = nextConfig
|
|
```
|
|
|
|
Supported units: `b`, `kb`, `mb`, `gb`
|
|
|
|
### Number format
|
|
|
|
Alternatively, specify the size in bytes as a number:
|
|
|
|
```ts filename="next.config.ts" switcher
|
|
import type { NextConfig } from 'next'
|
|
|
|
const nextConfig: NextConfig = {
|
|
experimental: {
|
|
proxyClientMaxBodySize: 1048576, // 1MB in bytes
|
|
},
|
|
}
|
|
|
|
export default nextConfig
|
|
```
|
|
|
|
```js filename="next.config.js" switcher
|
|
/** @type {import('next').NextConfig} */
|
|
const nextConfig = {
|
|
experimental: {
|
|
proxyClientMaxBodySize: 1048576, // 1MB in bytes
|
|
},
|
|
}
|
|
|
|
module.exports = nextConfig
|
|
```
|
|
|
|
## Behavior
|
|
|
|
When a request body exceeds the configured limit:
|
|
|
|
1. Next.js will buffer only the first N bytes (up to the limit)
|
|
2. A warning will be logged to the console indicating the route that exceeded the limit
|
|
3. The request will continue processing normally, but only the partial body will be available
|
|
4. The request will **not** fail or return an error to the client
|
|
|
|
If your application needs to process the full request body, you should either:
|
|
|
|
- Increase the `proxyClientMaxBodySize` limit
|
|
- Handle the partial body gracefully in your application logic
|
|
|
|
## Example
|
|
|
|
```ts filename="proxy.ts"
|
|
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
export async function proxy(request: NextRequest) {
|
|
// Next.js automatically buffers the body with the configured size limit
|
|
// You can read the body in proxy...
|
|
const body = await request.text()
|
|
|
|
// If the body exceeded the limit, only partial data will be available
|
|
console.log('Body size:', body.length)
|
|
|
|
return NextResponse.next()
|
|
}
|
|
```
|
|
|
|
```ts filename="app/api/upload/route.ts"
|
|
import { NextRequest, NextResponse } from 'next/server'
|
|
|
|
export async function POST(request: NextRequest) {
|
|
// ...and the body is still available in your route handler
|
|
const body = await request.text()
|
|
|
|
console.log('Body in route handler:', body.length)
|
|
|
|
return NextResponse.json({ received: body.length })
|
|
}
|
|
```
|
|
|
|
## Good to know
|
|
|
|
- This setting only applies when proxy is used in your application
|
|
- The default limit of 10MB is designed to balance memory usage and typical use cases
|
|
- The limit applies per-request, not globally across all concurrent requests
|
|
- For applications handling large file uploads, consider increasing the limit accordingly
|