# 错误：服务器操作负载超过最大大小限制（4MB）。

- **ID:** `nextjs/server-action-body-size-exceeded`
- **领域:** nextjs
- **类别:** data_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

服务器操作的默认主体大小限制为 4MB；上传大文件或发送大型 FormData 对象会触发此错误。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| next@14.0.0 | active | — | — |
| next@14.1.0 | active | — | — |
| next@15.0.0 | active | — | — |

## 解决方案

1. ```
   在 next.config.js 中增加特定服务器操作路由的主体大小限制：

export default {
  experimental: {
    serverActions: {
      bodySizeLimit: '10mb',
    },
  },
};

或者使用配置导出为每个操作设置：export const config = { api: { bodyParser: { sizeLimit: '10mb' } } };
   ```
2. ```
   使用预签名 URL 将大文件直接上传到云存储服务（例如 S3），只将文件引用发送到服务器操作。
   ```
3. ```
   在客户端实现分块上传，将文件的一部分作为单独的服务器操作发送，然后在服务器上重新组装。
   ```

## 无效尝试

- **** — This works but may not be allowed in some hosting environments; also, it's a security risk if not carefully scoped. (40% 失败率)
- **** — Server Actions expect FormData; compression breaks the form structure unless handled server-side. (70% 失败率)
- **** — This adds complexity and may cause race conditions or partial failures without proper transaction handling. (60% 失败率)
