что я хочу сделать здесь, это проверить файлы перед их загрузкой на сервер, не обновляя и не удаляя файлы, есть ли какое-то решение для этого,
const formidable = require('formidable');
const storage = multer.diskStorage({
....
})
router.post("/users/signup",
UserAuth.signUp,
multer({
storage ,
limits
}).fields([
{ name: 'profile', maxCount: 1 },
{ name: 'licence', maxCount: 1 },
]) , UserAuth.signUpSuccess);
class UserAuth {
static async signUp(req,res,next){
try{
const form = new formidable({multiples: true});
form.parse(req, function(err, fields, files) {
if (Object.keys(files).length === 7 && Object.keys(fields).length === 8 ) {
if(
files.hasOwnProperty("profile") && files["profile"].size !== 0 &&
files.hasOwnProperty("licence") && files["licence"].size !== 0 &&
){
save the record here and then call next() for multer to finish uploading the images after they all exist
}else{
throw Error("some field or file is missing")
}
}
});
}catch (error) {
console.log(error)
}
}
}