上传大文件时的ERR_CONNECTION_NULL nodejs multer

cedebl8k  于 11个月前  发布在  Node.js
关注(0)|答案(2)|浏览(124)

我正在写一个Web应用程序,允许用户上传非常大的文件(高达GB)。我的技术栈包括:nodejs,express,multer和纯html。它适用于小文件。但当我上传大文件(127 MB)时,我等待了一段时间(约2分钟)后得到错误ERR_CONNECTION_ERROR
我试过在服务器上使用req.setbacks和res.setbacks来延长响应时间,但是没有用。这可能是因为前端等待响应的时间太长了。
下面是我得到的错误:


的数据
谢谢你们

hfsqlsce

hfsqlsce1#

增加相应的upload-route的res-timeout肯定会起作用。试着这样做:

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
})

字符串

ghhaqwfi

ghhaqwfi2#

经过几个小时的调试,我终于得到了一个工作解决方案:
关键是提高server.requestTimeoutserver.headersTimeout的值
服务器上的文件头文件名:
最小值在server.requestTimeout或60000之间。

相关问题