diff --git a/index.js b/index.js index 551fb1c..107b487 100644 --- a/index.js +++ b/index.js @@ -232,10 +232,14 @@ router.post('/upload', upload.single('file'), async ctx => { return } - const mimetype = ctx.request.file.mimetype + let mimetype = ctx.request.file.mimetype const type = await FileType.fromFile(ctx.request.file.path) + if (mimetype == "application/octet-stream" && type) { + mimetype = type.mime + } + if ((!type || !allowedTypes.includes(type.mime)) && !allowedTypes.includes(mimetype)) { flash(ctx, { message: 'Uploaded file is of an invalid type: ' + ctx.request.file.originalname + ' (' + (type? type.mime : 'unknown mimetype') + ')',