Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error not received in callback #16

Open
neer14 opened this issue Mar 18, 2020 · 1 comment
Open

Error not received in callback #16

neer14 opened this issue Mar 18, 2020 · 1 comment

Comments

@neer14
Copy link

neer14 commented Mar 18, 2020

Hi,
I am not able to handle errors for multiple files .fields([{ name: 'files', maxCount: 10 }]) in multer

  limits: {
    fileSize: process.env.MAX_FILE_SIZE
  },
  fileFilter: (req, file, cb) => {
    if (this.validateExt(file.originalname)
    ) {
      req.filesArr.push(file);
      return cb(null, true);
    }
    return cb({ code: 'WRONG_FILE_MIMETYPE' });
  },
  storage: multerGoogleStorage.storageEngine({
    keyFilename:  '../gcp-keys.json',
    filename: (req, file, cb) => {
      const fileExt = file.originalname.match(/\.[a-z]+$/);
      const newFileName = `${file.originalname.split('.')[0].slice(0, 15)}_${Date.now()}${
        fileExt ? fileExt[0] : ''
      }`;
      return cb(null, `upload/${newFileName.replace(/ /g, '_')}`);
    }
  })
});
const processUpload = upload.fields([{ name: 'files', maxCount: 10 }]);
          processUpload(req, res, err => {
--------> error is received here if GCS credentials are false,but if GCS credentials are true then error is not received.
            if (err) {
              return reject(err);
            }
            return resolve(req.files);
          });
@dominathan
Copy link

👍 Upvoting this solution because I had to do this in my fork a well. Otherwise limits.fileSize does not produce an error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants