Advertisement
rickyc81

Untitled

Feb 19th, 2021
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require('path')
  2.  
  3. function checkFile(req, file, cb){
  4.    
  5.     // Allowed ext
  6.     const filetypes = /zip/;
  7.     // String Syntax
  8.     const stringSyntax = new RegExp(/^99(MEX|MEY|IEB|IEC)\d{6}_\d{12}\.zip$/im)
  9.     // Check ext
  10.     const extname = filetypes.test(path.extname(file.originalname).toLowerCase());
  11.     // Check mime
  12.     const mimetype = filetypes.test(file.mimetype);
  13.     // Check Syntax
  14.     const syntax = stringSyntax.test(path.extname(file.originalname).toLowerCase())
  15.  
  16.     console.log(file.originalname)
  17.     console.log(syntax)
  18.  
  19.    
  20.     if(mimetype){
  21.       return cb(null,true);
  22.     } else {
  23.       cb('Error: .zip only or syntax error!');
  24.     }
  25.   }
  26.  
  27.   module.exports = checkFile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement