richardgirges / express-fileupload

Simple express file upload middleware that wraps around busboy
MIT License
1.52k stars 261 forks source link

When doing a long upload I get the error ERR_CONNECTION_ABORTED #247

Closed ismailyagci closed 3 years ago

ismailyagci commented 3 years ago

When doing a long upload, I get the error ERR_CONNECTION_ABORTED after approximately 220 seconds.

My API

import fileUpload from "express-fileupload";
const port = process.env.PORT || 4000;
const app = express();
app.use(fileUpload({
    useTempFiles: true,
    uploadTimeout: 3600000
}));
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

app.post('/upload', function (req, res) {
    if (!req.files || Object.keys(req.files).length === 0) {
        return res.status(400).send('No files were uploaded.');
    }
    console.log(req)
    // The name of the input field (i.e. "sampleFile") is used to retrieve the uploaded file
    let sampleFile = req.files.sampleFile;
    var fileName = req.files.sampleFile.name;

    // Use the mv() method to place the file somewhere on your server
    sampleFile.mv(__dirname + '/source/uploadedFreeSounds/' + fileName, function (err) {
        if (err) {
            console.log(err)
            return res.status(500).send(err);
        }

        res.send('File uploaded!');
    });
});

const server = app.listen(port, () => {
    //createSecretToken(await r.uuid());
    console.log('Server start on localhost:' + port);
});
server.on('connection', function (socket) {
    // 10 minutes timeout
    socket.setTimeout(3600000);
});

My Client

<html>
  <body>
    <form ref='uploadForm' 
      id='uploadForm' 
      action='http://xx.xxx.xxx.xxx:4000/upload' 
      method='post' 
      encType="multipart/form-data">
        <input type="file" name="sampleFile" />
        <input type='submit' value='Upload!' />
    </form>     
  </body>
</html>

Please help me

ismailyagci commented 3 years ago

@richardgirges do you have any idea?

ismailyagci commented 3 years ago

Friends have had the same problem After working for 15 days, the source of the problem is "server.headersTimeout = 7200000;" you can fix it by adding this code