From 8e9922bd920814caea4670226fa8cbac2a040373 Mon Sep 17 00:00:00 2001 From: Mateja Date: Sun, 11 Jul 2021 16:12:59 +0200 Subject: Accept only images with max size of 10MB. --- server/lib/middleware.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'server/lib') diff --git a/server/lib/middleware.js b/server/lib/middleware.js index 735fddb..292c372 100644 --- a/server/lib/middleware.js +++ b/server/lib/middleware.js @@ -21,7 +21,19 @@ const multerStorage = multer.diskStorage({ cb(null, uuid.v4() + path.extname(file.originalname)); } }); -const upload = multer({storage: multerStorage}); +const multerFileFilter = (req, file, cb) => { + if (file.mimetype === 'image/png' || file.mimetype === 'image/jpeg' || file.mimetype === 'image/jpg') + cb(null, true); + else + cb(null, false); +}; +const upload = multer({ + storage: multerStorage, + limits: { + fileSize: 1024 * 1024 * 10 //10MB + }, + fileFilter: multerFileFilter +}); module.exports = { -- cgit v1.2.3