[英]ERR_CONNECTION_RESET when upload large file nodejs multer
I'm writing an web application that allow user to upload very large file (up to GB).我正在编写一个 web 应用程序,允许用户上传非常大的文件(高达 GB)。 My technical stack include: nodejs, express, multer and pure html.
我的技术堆栈包括:nodejs、express、multer 和纯 html。 It works fine for small file.
它适用于小文件。 But when I upload big file (127 MB), I got error ERR_CONNECTION_RESET after waiting a while (about 2 minutes ).
但是当我上传大文件(127 MB)时,等待一段时间(大约2 分钟)后出现错误ERR_CONNECTION_RESET 。
I tried extended response time on server, using both req.setTimeout and res.setTimeout but it didn't help.我尝试在服务器上延长响应时间,同时使用 req.setTimeout 和 res.setTimeout 但它没有帮助。 It's may be because frontend waiting to long to get response.
这可能是因为前端等待很长时间才能得到响应。
Below is the error I got:以下是我得到的错误:
Thank you all.谢谢你们。
Increasing the res
-timeout for the corresponding upload-route should definitely work.增加相应上传路由的
res
-timeout 肯定会起作用。 Try doing it like this:尝试这样做:
function extendTimeout (req, res, next) {
// adjust the value for the timeout, here it's set to 3 minutes
res.setTimeout(180000, () => { // you can handle the timeout error here })
next();
})
app.post('/your-upload-route', extendTimeout, upload.single('your-file'), (req, res, next) => {
// handle file upload
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.