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

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

Description

@AzrizHaziq

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions