From 193d52c06fe66d89540cac5e34caa8a263a8c725 Mon Sep 17 00:00:00 2001 From: Maia Teegarden Date: Fri, 2 Jul 2021 15:31:34 -0700 Subject: [PATCH 1/2] 5MB -> 4MB body size limit --- errors/api-routes-body-size-limit.md | 6 +++--- packages/next/server/api-utils.ts | 4 ++-- test/integration/api-support/test/index.test.js | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/errors/api-routes-body-size-limit.md b/errors/api-routes-body-size-limit.md index 10636b93cf281..58896c8e7388a 100644 --- a/errors/api-routes-body-size-limit.md +++ b/errors/api-routes-body-size-limit.md @@ -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 diff --git a/packages/next/server/api-utils.ts b/packages/next/server/api-utils.ts index c64644080ade4..d82d9d6ea5378 100644 --- a/packages/next/server/api-utils.ts +++ b/packages/next/server/api-utils.ts @@ -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` ) } diff --git a/test/integration/api-support/test/index.test.js b/test/integration/api-support/test/index.test.js index 62a559fffce71..93b18fb91014e 100644 --- a/test/integration/api-support/test/index.test.js +++ b/test/integration/api-support/test/index.test.js @@ -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.' ) }) From a4fbc634626e5b8e5336a437f6add1c935666206 Mon Sep 17 00:00:00 2001 From: Maia Teegarden Date: Fri, 2 Jul 2021 15:41:04 -0700 Subject: [PATCH 2/2] Update errors/api-routes-body-size-limit.md Co-authored-by: Steven --- errors/api-routes-body-size-limit.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errors/api-routes-body-size-limit.md b/errors/api-routes-body-size-limit.md index 58896c8e7388a..5697768c4a089 100644 --- a/errors/api-routes-body-size-limit.md +++ b/errors/api-routes-body-size-limit.md @@ -1,4 +1,4 @@ -# API Routes Body Size Limited to 4mb +# API Routes Body Size Limited to 4MB #### Why This Error Occurred