Closed andydam closed 5 months ago
Yeah parsing form data is currently not very well supported, thanks for reporting. As Next.js docs directly recommends using zod-form-data
to parse form data, I think it could be well integrated to this framework as it already highly leverages Zod, I'll look into it 👍🏻
Hey, v6.0.0-beta.1
is now released that introduces overall better, stronly-typed form data support, also for RPC routes. There's an example on how to use form data with RPC routes now, hope this resolves your issue: https://github.com/blomqma/next-rest-framework?tab=readme-ov-file#rpc-endpoints
I've created an
rpcOperation
that takes inFormData
for uploading files and it seems to work fine when called as a Server Action (although with a type error in.input()
args probably due tozod-form-data
)Example:
When using
rpcRoute
with App Router to access thisrpcOperation
outside of a Server Action fails though, with aresponse since
rpcRoute
only supports JSON. It would be great ifmultipart/form-data
requests were supported, either built into the framework by passing App Router'srequest.formData()
(https://nextjs.org/docs/app/building-your-application/routing/route-handlers#request-body-formdata) into the validator whencontent-type
ismultipart/form-data
or having some way to override the JSON parsing inrpcRoute
with custom handling to supportmultipart/form-data