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

App router Increase body size limit Api routes #57501

Closed
1 task done
Biratus opened this issue Oct 26, 2023 · 4 comments
Closed
1 task done

App router Increase body size limit Api routes #57501

Biratus opened this issue Oct 26, 2023 · 4 comments
Labels
bug Issue was opened via the bug report template. locked

Comments

@Biratus
Copy link

Biratus commented Oct 26, 2023

Link to the code that reproduces this issue

https://codesandbox.io/s/next-with-api-forked-6cs9k8?file=/pages/api/test.js

To Reproduce

I am reopening the issue #52457 because the final comment : #52457 (comment) was not answered.

Use the link https://codesandbox.io/s/next-with-api-forked-6cs9k8?file=/pages/api/test.js to reproduce

Current vs. Expected behavior

In the pages router we can modify the body size limit with:

export const config = {
  api: {
    bodyParser: {
      sizeLimit: "5mb",
    },
  },
};

However there is no equivalent in the App Router. It does work in development mode but fails during the build

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #97~20.04.1-Ubuntu SMP Thu Oct 5 08:25:28 UTC 2023
Binaries:
  Node: 16.16.0
  npm: 8.11.0
  Yarn: 1.22.19
  pnpm: N/A
Relevant Packages:
  next: 13.5.6
  eslint-config-next: 13.4.7
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.6
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router

Additional context

To increase the body limit, do we need to define the api route the old way on the page router (so we can use export config) or is there an alternative in the app router ?

@Biratus Biratus added the bug Issue was opened via the bug report template. label Oct 26, 2023
@aryobenholzner
Copy link

Can please someone from the Next.js team answer this.
With pages API route it is possible, with server actions we can do it. There is nothing documented for app routers route handlers. Is there anything undocumented or do we need to fallback to pages or server actions?

@shuding
Copy link
Member

shuding commented Nov 20, 2023

You can use the experimental.serverActions.bodySizeLimit option:

https://nextjs.org/docs/app/api-reference/functions/server-actions#size-limitation

@shuding shuding closed this as completed Nov 20, 2023
@TryingToImprove
Copy link
Contributor

I have a problem like this for server actions.. @shuding

Configured like this

/** @type {import('next').NextConfig} */
const nextConfig = {
    experimental: {
        serverActions: {
            bodySizeLimit: '500mb'
        }
    },
}

module.exports = nextConfig

and sending a large hidden input field caps the string at 1040434 chars however I can see that there is much more data in the payload but

 async function create(formData: FormData) {
    "use server";
    console.log(formData.get("document")?.toString().length);

don't get it all..

Copy link
Contributor

github-actions bot commented Dec 4, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Dec 4, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests

4 participants