diff --git a/server/src/middlewares/upload.js b/server/src/middlewares/upload.js index a01c6881..28fcaa15 100644 --- a/server/src/middlewares/upload.js +++ b/server/src/middlewares/upload.js @@ -22,6 +22,7 @@ const storage = multer.diskStorage({ const upload = multer({ storage, + limits: { fileSize: 1 * 1024 * 1024 }, // 1MB limit fileFilter(req, file, callback) { if (file.mimetype == 'application/pdf') { callback(null, true); @@ -30,13 +31,25 @@ const upload = multer({ callback(null, false); } }, -}); +}).single('waiver'); + +router.post('/upload-waiver', (req, res) => { + upload(req, res, (err) => { + if (err instanceof multer.MulterError) { + if (err.code === 'LIMIT_FILE_SIZE') { + return res.status(400).send('File is too large. Maximum size is 1MB.'); + } + return res.status(400).send('An error occurred while uploading the file.'); + } else if (err) { + return res.status(400).send('An unknown error occurred.'); + } -router.post('/upload-waiver', upload.single('waiver'), (req, res) => { - if (!req.file) { - return res.status(400).send('No file uploaded.'); - } - res.status(200).send('File uploaded successfully.'); + // all good + if (!req.file) { + return res.status(400).send('No file uploaded.'); + } + res.status(200).send('File uploaded successfully.'); + }); }); module.exports = router; diff --git a/server/src/uploads/Gaurika_Mahajan_Retreat_Waiver.pdf b/server/src/uploads/Gaurika_Mahajan_Retreat_Waiver.pdf deleted file mode 100644 index c3336b72..00000000 Binary files a/server/src/uploads/Gaurika_Mahajan_Retreat_Waiver.pdf and /dev/null differ