zod
zod copied to clipboard
Type "string" format "binary"
Hello guys, I tried to upload a file using zod validator, this must be run also on Swagger
body: {
type: 'object',
properties: {
file: {
type: 'string',
format: 'binary',
},
},
},
How to set with zod an object similar ? Thank's
You might be able to achieve this by using a refinement.
z.string().refine((str): str is Buffer => Buffer.isBuffer(Buffer.from(str)))
I'm not used to working with binary data, but I think that would work.
Let me know.
BR.
The question is whether in your instance you really need to validate the binary raw, not first process it into some representation. Because you can also check for z.instanceOf
and then refine
it. For example on a remix app I'm first processing multipart and produce File
then can check z.instanceOf(File).refine(file => /* ... */)
. Substitute File
with whatever data you have.
@clabnet ok to mark this as resolved?
Yes close it, thank's
Hello guys I tried to do This
z.string().refine((str): str is Buffer => Buffer.isBuffer(Buffer.from(str)))
But it didn't work Swagger still read it as a text input rather than file picker
@clabnet @santosmarco-caribou