Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: support multipart/form-data responses #471

Open
eric-carlsson opened this issue Aug 29, 2023 · 2 comments · May be fixed by #472
Open

feature request: support multipart/form-data responses #471

eric-carlsson opened this issue Aug 29, 2023 · 2 comments · May be fixed by #472

Comments

@eric-carlsson
Copy link
Contributor

multipart/form-data is currently not supported as a response type, and operations that have this response type will instead default to blob. This can be converted to formData without data loss, but it's ugly:

  const res = await handle(getPet(petID), {
    200: (pet) => pet
  });

  const contentType = res.headers.get('Content-Type') as string;

  const r = new Response(res.data as unknown as FormData, {
    headers: { 'Content-Type': contentType }
  });

  const formData = await r.formData();

  const d = Object.fromEntries(formData.entries()) as unknown as Pet;

The Responses API supports directly parsing the body as FormData, so there's really no reason to not support it.

@eric-carlsson
Copy link
Contributor Author

This should be fairly straight forward to implement, so I can give it a shot. Expect a PR shortly.

@Xiphe
Copy link
Collaborator

Xiphe commented Aug 29, 2023

Cool! Looking forward to that 👍

@eric-carlsson eric-carlsson linked a pull request Aug 30, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants