How to annotate the type of a streamed file response #78
-
I'm looking at moving my apis over to use express-zod-api however one endpoint returns large zipped files using res.sendFile() . |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
Hello @Utopianii , thank you for the question. Short answer: please use string for now. I was also researching the similar question and here I'm ready to share my results with you.
Additional clarifications The I hope that I was able to provide you with useful information for your project. |
Beta Was this translation helpful? Give feedback.
-
P.S. The given example is a part of the v2, which is currently beta and available for installation using tag yarn add express-zod-api@beta Stable release scheduled in a week. |
Beta Was this translation helpful? Give feedback.
-
@Utopianii , I made the file streaming implementation example for you in this PR: #76 |
Beta Was this translation helpful? Give feedback.
-
Thank you, yes that answers my question. |
Beta Was this translation helpful? Give feedback.
-
I've added // before
const fileStreamingEndpointsFactoryBefore = new EndpointsFactory(createResultHandler({
getPositiveResponse: () => createApiResponse(z.string(), 'image/*'),
...
}));
// after
const fileStreamingEndpointsFactoryAfter = new EndpointsFactory(createResultHandler({
getPositiveResponse: () => createApiResponse(z.file().binary(), 'image/*'),
...
})); CC @Utopianii |
Beta Was this translation helpful? Give feedback.
Hello @Utopianii , thank you for the question.
Short answer: please use string for now.
I was also researching the similar question and here I'm ready to share my results with you.
z.string()
(ZodString
type). In theory, it's possible to create a custom type by inheriting fromZodType<>
generic inferringReadableStream
, and implementing own_parse()
method for validation, but I decided that this is an unnecessary complication at this stage.