Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5MB -> 4MB body size limit #26887

Merged
merged 2 commits into from
Jul 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions errors/api-routes-body-size-limit.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# API Routes Body Size Limited to 5mb
# API Routes Body Size Limited to 4MB

#### Why This Error Occurred

API Routes are meant to respond quickly and are not intended to support responding with large amounts of data. The maximum size of responses is 5 MB.
API Routes are meant to respond quickly and are not intended to support responding with large amounts of data. The maximum size of responses is 4 MB.

#### Possible Ways to Fix It

Limit your API Route responses to less than 5 MB. If you need to support sending large files to the client, you should consider using a dedicated media host for those assets. See link below for suggestions.
Limit your API Route responses to less than 4 MB. If you need to support sending large files to the client, you should consider using a dedicated media host for those assets. See link below for suggestions.

### Useful Links

Expand Down
4 changes: 2 additions & 2 deletions packages/next/server/api-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export async function apiResolver(
contentLength += Buffer.byteLength(args[0])
}

if (contentLength >= 5 * 1024 * 1024) {
if (contentLength >= 4 * 1024 * 1024) {
console.warn(
`API response for ${req.url} exceeds 5MB. This will cause the request to fail in a future version. https://nextjs.org/docs/messages/api-routes-body-size-limit`
`API response for ${req.url} exceeds 4MB. This will cause the request to fail in a future version. https://nextjs.org/docs/messages/api-routes-body-size-limit`
)
}

Expand Down
6 changes: 3 additions & 3 deletions test/integration/api-support/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,17 +398,17 @@ function runTests(dev = false) {
expect(data).toBe('hi')
})

it('should warn if response body is larger than 5MB', async () => {
it('should warn if response body is larger than 4MB', async () => {
let res = await fetchViaHTTP(appPort, '/api/large-response')
expect(res.ok).toBeTruthy()
expect(stderr).toContain(
'API response for /api/large-response exceeds 5MB. This will cause the request to fail in a future version.'
'API response for /api/large-response exceeds 4MB. This will cause the request to fail in a future version.'
)

res = await fetchViaHTTP(appPort, '/api/large-chunked-response')
expect(res.ok).toBeTruthy()
expect(stderr).toContain(
'API response for /api/large-chunked-response exceeds 5MB. This will cause the request to fail in a future version.'
'API response for /api/large-chunked-response exceeds 4MB. This will cause the request to fail in a future version.'
)
})

Expand Down