Strapi Body-Parser 文件大小设置

Strapi Body-Parser File Size Settings

我正在尝试将文件上传到 Strapi API,但我一直收到文件过大的错误消息。我想发送一个 1mb 的文件。通常在 Express/Koa 中,我可以像这样更改 body-parser 设置:

app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));

但是由于 Strapi 是一个封闭的系统,我不确定在哪里设置或编辑它。

非常感谢所有帮助和指点! :)

您可以更改解析器中间件中的设置。
来自 docs:

The library we use is koa-body, and itself uses the node-formidable library to process files.
You can pass configuration to the middleware directly by setting it in the parser middleware configuration

地点:
./config/request.json(稳定)
./config/environments/development/request.json(预稳定)

{
  "parser": {
    //Other settings
    //...
    //This is what you're looking for
    "formidable": {
      "maxFileSize": 20000000 // defaults to 200mb
    }
  }
}

在 v3.x.x 中,设置现在显然位于 ./config/middleware.js

事实证明,增加文件大小是不够的,您还必须确保 formLimitjsonLimit 也增加。

    parser: {
        //..
        formLimit: '50mb', <--
        jsonLimit: '50mb', <--
        formidable: {
            maxFileSize: 50 * 1024 * 1024, // 50MB
        },
    },