Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require('path')
- function checkFile(req, file, cb){
- // Allowed ext
- const filetypes = /zip/;
- // String Syntax
- const stringSyntax = new RegExp(/^99(MEX|MEY|IEB|IEC)\d{6}_\d{12}\.zip$/im)
- // Check ext
- const extname = filetypes.test(path.extname(file.originalname).toLowerCase());
- // Check mime
- const mimetype = filetypes.test(file.mimetype);
- // Check Syntax
- const syntax = stringSyntax.test(path.extname(file.originalname).toLowerCase())
- console.log(file.originalname)
- console.log(syntax)
- if(mimetype){
- return cb(null,true);
- } else {
- cb('Error: .zip only or syntax error!');
- }
- }
- module.exports = checkFile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement