arb / celebrate

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

How to validate file extension (.mp3, wmv) #54

Closed manjeettahkur closed 7 years ago

manjeettahkur commented 7 years ago

how to validate file extension with Celebrate Joi,

My Joi schema is like this

body: Joi.object().keys({ Audio: Joi.string().regex(/\.(?:wav|mp3)$/i).optional().options({ language: { any: { allowOnly: 'request id is required' }, label: 'audio file' } }).label('please provide [.mp3] or [.wav] file'), indexname: Joi.string().required() })

in audio my file is attached

curl -X POST --header 'Content-Type: multipart/form-data' --header 'Accept: application/json' -F Audio=@"33107045414_f1b635aea6_k.jpg" -F indexname=1222 'http://172.24.5.22:3000/api/v1/audio'

so how can i validate file format with the help of joi regex function

cjihrig commented 7 years ago

Is this an issue with celebrate, or a general support question about using joi? If it's about using joi, I'd suggest experimenting with the schema at https://npm.runkit.com/joi, or asking on the joi issue tracker. Also, see https://github.com/continuationlabs/celebrate#issues.

Thanks, and good luck.

Marsup commented 7 years ago

You could try me but I have no idea how express' payload parser ends up converting it, so you're on your own.

manjeettahkur commented 7 years ago

Thanks @Marsup i solve this issue.