[英]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.