0

I'm writing an web application that allow user to upload very large file (up to GB). My technical stack include: nodejs, express, multer and pure 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).

I tried extended response time on server, using both req.setTimeout and res.setTimeout but it didn't help. It's may be because frontend waiting to long to get response.

Below is the error I got:

enter image description here

Thank you all.

Akkien
  • 84
  • 11

1 Answers1

0

Increasing the res-timeout for the corresponding upload-route should definitely work. 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
})
eol
  • 23,236
  • 5
  • 46
  • 64
  • I already tried res.setTimeout and req.setTimeout, but it not worked. I think frontend want to hear some response in short time, not wait ultil file is uploaded. – Akkien Aug 20 '20 at 07:34
  • Have you tried it like this? If yes, you probably need to adjust the request-timeout in the client. – eol Aug 20 '20 at 07:48
  • I tried using axios at frontend but it still didn't work. – Akkien Aug 20 '20 at 08:56
  • Can you add your code and show how you set the timeout in node and on the client-side? – eol Aug 20 '20 at 08:58