Handling Large File Uploads in Node.js with Multer - Timeout Issues
I'm experimenting with I'm writing unit tests and I'm relatively new to this, so bear with me... I'm working on a personal project and I'm experiencing timeout issues when attempting to upload large files (around 100MB) using Multer in my Node.js application... My server is set up with Express and I'm using Multer for handling multipart/form-data, but when I try to upload larger files, the request times out before completing. I've set a custom timeout for my server using `server.setTimeout(300000);` (5 minutes), but it still seems to stall. Hereโs a snippet of how I set up Multer: ```javascript const express = require('express'); const multer = require('multer'); const app = express(); const storage = multer.diskStorage({ destination: function (req, file, cb) { cb(null, 'uploads/') }, filename: function (req, file, cb) { cb(null, file.originalname) } }); const upload = multer({ storage: storage, limits: { fileSize: 100 * 1024 * 1024 } // 100MB limit }); app.post('/upload', upload.single('file'), (req, res) => { res.send('File uploaded successfully.'); }); app.listen(3000, () => { console.log('Server is running on port 3000'); }); ``` When I try to upload a file over 50MB, it just hangs, and I get a `504 Gateway Timeout` behavior on the client side. Iโve also tried increasing the file size limit in Multer, but it didnโt help. Additionally, I checked the server logs and there are no errors logged when the timeout occurs. Iโm using Node.js version 16.x and Express version 4.17.x. Any suggestions on how to handle large file uploads effectively without hitting timeouts? This is part of a larger service I'm building. Any ideas what could be causing this? Could this be a known issue? For reference, this is a production desktop app. Is there a simpler solution I'm overlooking? The project is a service built with Javascript.