Answers for "custom validation express validator"

0

custom validator express validator

body("thumbnail_file").custom(async (value, { req }) => {
  const thumbnailFile = req.files && req.files.thumbnail_file;
  if (!thumbnailFile) {
    return true;
  } else if (Array.isArray(thumbnailFile)) {
    throw new Error("Only one thumbnail file is allowed.");
  }
  if (
    thumbnailFile.mimetype !== "image/png" &&
    thumbnailFile.mimetype !== "image/jpg" &&
    thumbnailFile.mimetype !== "image/jpeg"
  ) {
    throw new Error(
      "Only .png, .jpg and .jpeg image formats are allowed for thumbnail file."
    );
  }
}),
Posted by: Guest on April-14-2022

Code answers related to "custom validation express validator"

Browse Popular Code Answers by Language