I have a node/express app that handles file uploads with multer. Everything works well on my local machine, but on the server, if the uploaded file exceeds a couple of Mbs, the browser stops with a "connection reset" error.
Here is a simple test version of the upload script:
var express = require('express');
var multer = require('multer');
// Create server
var app = express();
// Start server
function startServer() {
var port = 8888;
server = app.listen(port, function () {
console.log('Node version:' + process.versions.node);
console.log('Express server listening on port %d in %s mode', port, app.settings.env);
});
}
var upload = multer({dest: './tmp/'});
var app = express()
app.post('/', upload.single('data'), function (req, res, next) {
console.log(req.file);
});
startServer();
And here's the html page to test the upload:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>Test Upload</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<p>Hello world! This is a test upload.</p>
<form method="post" action="http://192.168.1.234:8888" enctype="multipart/form-data">
<label>file</label><br>
<input type="file" name="data"><br>
<input type="submit" name="submit" value="Upload">
</form>
</body>
</html>
I tested on two different servers – a VPS and a bare-metal box – I ended up with the same error on both servers. The upload starts and I can see a chunck of the file in my ./tmp
directory, but it never finishes and doesn't throw any error, neither in node nor in the syslog.