当我将文件大小超过 1MB 的数组发送到 Next.js 服务器时,我会得到
Body exceeded 1 MB limit
:
我尝试通过在
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.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;