NextJS 抛出 413 Payload Too Large

问题描述 投票:0回答:1

有一个处理 CSV 文件的 API 路由,

我有一个大小为 12MB 的文件。当我上传它时,它会抛出此错误:413 Payload Too Large 请求太大,服务器无法处理。

根据文档,可以使用 config as 更改此设置,

export const config = {
  api: {
    bodyParser: {
      sizeLimit: '15mb',
    },
  },
};

但这会引发构建错误,

Error: Page config in api/route.ts is deprecated. Replace `export const config=…` with the following:
Visit https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config for more information.

并且没有切换 bodySizeLimit 的选项。

这些文档相互矛盾且令人困惑。感谢帮助。

next.js nextjs14 http-status-code-413
1个回答
0
投票

旧的 config 方法用于 pages 目录中的 Next.js 中,为每个 API 路由设置特定配置。但是,对于 Next.js 13 及更高版本,config 设置无法在应用程序目录中以这种方式应用。

您可以使用这个强大的库; 请检查这个

© www.soinside.com 2019 - 2024. All rights reserved.