gpt4 book ai didi

node.js - 招摇生成 Nodejs : Error: request entity too large

转载 作者:搜寻专家 更新时间:2023-10-31 22:20:28 24 4
gpt4 key购买 nike

使用 editor.swagger 生成的 Nodejs 代码在正文中我想发送 10mb 但无法发送,我收到此错误:

Error: request entity too large
at makeError (c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\node_modules\body-parser\node_modules\raw-body\index.js:154:15)
at readStream (c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\node_modules\body-parser\node_modules\raw-body\index.js:188:15)
at getRawBody (c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\node_modules\body-parser\node_modules\raw-body\index.js:95:12)
at read (c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\node_modules\body-parser\lib\read.js:64:3)
at jsonParser (c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\node_modules\body-parser\lib\types\json.js:116:5)
at c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\middleware\swagger-metadata.js:72:9
at urlencodedParser (c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\node_modules\body-parser\lib\types\urlencoded.js:91:37)
at bodyParser (c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\middleware\swagger-metadata.js:68:5)
at c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\middleware\swagger-metadata.js:258:5
at c:\apigee\dojo\nodeServer_2\node\node_modules\swagger-tools\node_modules\async\lib\async.js:356:13

我已经尝试过这个选项,但仍然出现同样的错误。这是来自 index.js 的示例代码:

swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
app.use(middleware.swaggerMetadata());
/*app.use(middleware.swaggerMetadata(
bodyParser.json({limit: "50mb"}),
bodyParser.urlencoded({ limit: "50mb", extended: true })
)
);*/

// Validate Swagger requests
app.use(middleware.swaggerValidator());

// Route validated requests to appropriate controller
app.use(middleware.swaggerRouter(options));

// Serve the Swagger documents and Swagger UI
app.use(middleware.swaggerUi());

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

app.use(bodyParser.json({limit: 10 * 1024 * 1024}));
app.use(bodyParser.raw({limit: 10 * 1024 * 1024}));
app.use(bodyParser.text({limit: 10 * 1024 * 1024}));
app.use(bodyParser.urlencoded({limit: 10 * 1024 * 1024, extended: true}));

最佳答案

根据 https://github.com/apigee-127/swagger-tools/issues/248 中指定的说明,你想在初始化swagger之前配置bodyParser,像这样:

app.use(bodyParser.json({limit: 10 * 1024 * 1024}));
app.use(bodyParser.raw({limit: 10 * 1024 * 1024}));

app.use(require("./router")); // in this sample, this is where you configure your Swagger middleware

这样,Swagger 将在您设置的限制下使用您配置的 bodyParser。我正在解决同样的问题,这解决了它。

关于node.js - 招摇生成 Nodejs : Error: request entity too large,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34234666/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com