Add file size callback to apply-middleware.

This commit is contained in:
theADAMJR 2023-05-29 22:40:30 +01:00
parent 8c11a2ac4d
commit 42498c16b6

View File

@ -37,12 +37,13 @@ function setupMulter(app: Application) {
if (!allowedTypes.includes(ext))
return callback(new Error('This image file type is not allowed'));
const maxSize = 1024 * 1024;
if (file.size > maxSize)
const fileSize = parseInt(req.headers['content-length'] as string);
if (fileSize > 1024 * 1024)
return callback(new Error('File size not supported'));
callback(null, true);
},
limits: { fileSize: 1024 * 1024 }
});
app.post('/v2/upload', updateUser, validateUser, extraRateLimit(10), upload.single('file'), async (req, res) => {