Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

How to work with upload File, multipart/form-data #81

Open
AzrizHaziq opened this issue Nov 21, 2023 · 0 comments
Open

How to work with upload File, multipart/form-data #81

AzrizHaziq opened this issue Nov 21, 2023 · 0 comments

Comments

@AzrizHaziq
Copy link

Hi, would like to ask your opinion on how to upload a file using prpc.

here is snippet of mutation$

  createNew: mutation$({
    mutationFn: async ({ ctx$, payload }) => {
     // using drizzle
      await db.insert(schemas.tools).values({
        ...payload,
        createdBy: ctx$.session.user.id as unknown as string,
        createdAt: new Date()
      })

      return 'OK'
    },
    key: 'tool_createNew',
    schema: createToolScheme, // zod schema
    middlewares: [authMw],
  }),

and in my client side

   <form
        class="grid sm:grid-cols-2 gap-5"
        onSubmit={async (e) => {
          e.preventDefault()
          const fd = new FormData()
          fd.append('cert', file()) // this is File

          await createNew.mutateAsync(fd) // <--- does not accept formData
        }}>

createNew.mutateAsync i been looking for ways to send using formData instead of application/json but could not find any solution. Hence, would like to ask your opinion is there a way to work with formData.

it's been delightful using your work. Thank you

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant