'How to validate the array of CSV files that were received using the Multer and express-validator node module

When I use the "express-fileupload" node-module as middleware, I get the req.files structure like below as object,

{
  userList: {
    name: 'users-list.csv',
    data: <Buffer 22 68 63 6c 4e 68 more bytes>,
    size: 568,
    encoding: '7bit',
    tempFilePath: '',
    truncated: false,
    mimetype: 'text/csv',
    md5: '9bc816329306a1e64faac45fte432',
    mv: [Function: mv]
  }
}

I used express-validator, where I check the type of each file matching the CSV and, also converted the file from CSV file to JSON using express-validator customSanitizer, then I validated the JSON data fields.

But when I am using multer as global middleware in express JS app where I have given as,

app.use(
    multer({
       storage: multer.memoryStorage()
    }).any());

So, I am getting file details in req.files as an array,

[{
  fieldname: 'userList',
  originalname: 'user-list.csv',
  encoding: '7bit',
  mimetype: 'text/csv',
  buffer: <Buffer 22 518 more bytes>,
  size: 568
}]

Is it possible to achieve the same validation with the multer?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source