使用 Next.js 服务器时出现“错误:正文超出 1 MB 限制”

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

当我将文件大小超过 1MB 的数组发送到 Next.js 服务器时,我会得到

Body exceeded 1 MB limit
:

this error

我尝试通过在

next.config.js
中添加文件大小配置来解决此问题,但添加文件大小配置后就不起作用了。与服务器文件相同,仍然没有解决问题。

"use server"

import { connectToDatabase } from "@/mongodb/connectToMongo";

export default async({document={}})=>{
    const db = await connectToDatabase();
    const collection = db.collection("excels");
    const response=await collection.insertOne(document)
    const { insertedId } = response;
    return insertedId
}

export const config={
    api:{
        bodyParser:{
            sizeLimit:"10mb"
        }
    }
}
next.js
1个回答
0
投票

next.config.js

   /** @type {import('next').NextConfig} */
    const nextConfig = {
      reactStrictMode: false,
      experimental: {
        serverActions: {
          // 👇 change file size limit
          bodySizeLimit: 250, 
        },
        serverComponentsExternalPackages: ["@react-pdf/renderer"],
      },
      // 👇 to access images links globally
      images: {
        remotePatterns: [
          {
            protocol: "https",
            hostname: "**",
            port: "",
            pathname: "/**/**",
          },
        ],
      },
    };
    
    export default nextConfig;
© www.soinside.com 2019 - 2024. All rights reserved.