aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2021-07-11 16:12:59 +0200
committerMateja <mail@matejamaric.com>2021-07-11 16:12:59 +0200
commit8e9922bd920814caea4670226fa8cbac2a040373 (patch)
tree08dbe3c2286d07e0b8c7e4b7eb673b759584d3f5
parente5462f684aa33ddc2e2169147eece29bd38d3ae1 (diff)
downloadmevn-ecommerce-8e9922bd920814caea4670226fa8cbac2a040373.tar.gz
mevn-ecommerce-8e9922bd920814caea4670226fa8cbac2a040373.zip
Accept only images with max size of 10MB.
-rw-r--r--server/lib/middleware.js14
1 files changed, 13 insertions, 1 deletions
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 = {