Replies: 1 comment
-
Good idea! I agree we need something like this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have to keep this short because I'm on mobile, but I think we could enhance RPC spec to allow support for file uploads in mutations.
Background
File uploads create an awkward friction point because you end up having to fallback to API routes as soon as they are in your form. This could turn into a lot of work if you have an existing form that you're adding an upload to.
Solution
Since the existing spec expects an input that is application/json, we could support a multipart/form-data call where the first part is a .json file (containing the original JSON payload) and the following parts each get appended to the request context (e.g.
ctx.req.files[0]
).Proposal
If the request is multipart/form-data and the first part contains JSON data, then parse the first part using the existing RPC specification, and append the remaining parts to the request context as an array of files.
I'm not exactly sure what this would look like on the client-side, though. Perhaps the mutation handler could scan the input object for File or Blob values and automatically pull them out into separate parts, or add a separate useUploadMutation() hook that lets you append files.
For security, it is probably ideal if a mutation must opt in to allow multipart requests, such as:
Beta Was this translation helpful? Give feedback.
All reactions