0
if (file.mimetype.split('/')[0] !== 'image') {
cb(Error('Invalid file type'), false);
}
if (file.length > 20) {
cb(Error('File limit exceeded'), false);
}
cb(null, true);
};

let multipleUpload = multer({
 storage: multerS3({
  s3: s3,
  bucket: ENV_S3_BUCKET,
  acl: ENV_ACL_PRIVATE,
  contentType: multerS3.AUTO_CONTENT_TYPE,
  serverSideEncryption: 'AES256',
  key: function (req, file, cb) {
  const directoryName = "test";
  let fileExtension;
  if (file.mimetype.includes('image/')) {
  fileExtension = '.' + file.mimetype.split('/')[1];
  }
  cb(
  null,
  `${
  DIRECTORY
  }/${directoryName}/${Date.now()}_${fileExtension}`
  );
  }
 }),
 fileFilter
});
router.route('/upload').post(multipleUpload.array('resource', 20),DbAudit);

This is the code that i wrote on my router file as described on the Multer document and it is working fine, but when i move this to a middlewear and imported to my router file it is not working, i am not getting the file in req.file object.

i want to know what is going wrong, what is the mistake that i have done when moving it to other helper file?

i tried moving the code to other file and add it as the middlewear in my route but it is not working.

what does a multer function return?

0 Answers0