arb / celebrate

A joi validation middleware for Express.
MIT License
1.34k stars 65 forks source link

Validate multipart/form-data #223

Closed saymondamasio closed 3 years ago

saymondamasio commented 3 years ago

add file types, to validate the multipart/form-data that the multer creates

example:

const upload = multer(uploadConfig)

routes.post(
  '/orphanages',
  upload.array('images'),
  (req, res, next) => {
    console.log(req.files)
    return next()
  },
  celebrate({
    [Segments.BODY]: {
      name: Joi.string().required(),
      latitude: Joi.number().required(),
      longitude: Joi.number().required(),
      about: Joi.string().required().max(300),
      instructions: Joi.string().required(),
      opening_hours: Joi.string().required(),
      open_on_weekends: Joi.boolean().required(),
    },
    [Segments.FILES]: Joi.array().items({
      path: Joi.string().required(),
    }),
  }),
  new OrphanagesController().create,
)
Nikola-Milovic commented 2 years ago

This isn't implemented yet? How did you resolve it? @saymondamasio