From 907478e6f1e8e702975d213a33a75d9f700c5a59 Mon Sep 17 00:00:00 2001 From: Jack Date: Fri, 13 Oct 2017 18:07:52 -0400 Subject: [PATCH] Add file size verification in upload script --- app/routes/upload.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/routes/upload.js b/app/routes/upload.js index 8c6bcfe..c29c0d8 100644 --- a/app/routes/upload.js +++ b/app/routes/upload.js @@ -25,7 +25,13 @@ function genFileName() { router.post('/', dest.single('file'), function(req, res) { if (req.payload.scope.indexOf('file.upload') === -1) { - res.status(401).json({'message': 'Permission error.'}); + res.status(403).json({'message': 'Permission error.'}); + return; + } + + // Size must be below 128 Megabytes (1024*1024*128 Bytes) + if (req.file.size >= 134217728) { + res.status(413).json({'message': 'File too large.'}); return; }