![](/img/trans.png)
[英]nodejs app engine app error 413 Request Entity Too Large when upload a file
[英]413 (Request Entity Too Large) when attempting to upload a file express
我有一个简单的 POST 到/upload
express 端点。 小文件工作正常,但是,任何超过 2mb 的文件都会给我以下错误:
413请求实体太大)
有什么我缺少的东西需要添加才能工作吗? 这是我的代码的样子:
const { Router } = require('express')
const fileUpload = require('express-fileupload')
router.post('/upload', fileUpload(), function (req, res) {
console.log('I am never reached')
let uploadFile = req.files.file
const fileName = req.files.file.name
// do stuff
}
我究竟做错了什么? 在那之前我错过了另一个中间件吗? 我还应该注意,在fileUpload
,我尝试将其作为:
fileUpload({
limits: { fileSize: 50 * 1024 * 1024 },
})
但这没有帮助。 还有什么可能是错的?
编辑:这是我的获取代码,以防万一:
const data = new FormData()
data.append('file', file, file.name)
return isomorphicFetch(`/upload`, {
method: 'POST',
body: data
})
谢谢!
您可以在应用程序的主文件中尝试:
const express = require('express');
const app = express();
app.use(express.urlencoded({extended: false, limit:'100mb',parameterLimit:1000000 }));
我花了几个小时试图在我身边弄清楚。
无论我遵循的配置如何,我总是收到 413 作为状态代码,我意识到问题出在我的 kubernetes 集群中的 NGINX Ingress 中,然后我添加了:
...
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: 16m
这足以解决它。
我希望你也能帮助其他人解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.