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

Support multiple content types or allow custom response handling #70

Open
2 tasks done
matejm opened this issue Sep 5, 2023 · 1 comment
Open
2 tasks done

Support multiple content types or allow custom response handling #70

matejm opened this issue Sep 5, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@matejm
Copy link

matejm commented Sep 5, 2023

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

Currently, @supabase/functions-js package automatically handles JSON/text/multipart-form/blob parsing. However, this is done simply by checking if Content-Type if one of three predefined options (see functions-js source code). In all other cases, response is converted to text.

Example

Supabase has defined following edge function:

// read-pdf-file
serve(async (req) => {
  // read pdf file from S3 storage and return it as a response
  const pdfFile: Blob = ...
  return new Response(
    pdfFile,
    {
      headers: {
        // set correct content type
        "Content-Type": "application/pdf",
      },
    },
  );
});

When this function is invoked via Supabase client:

const { data } = await client.functions.invoke(f, { method: 'GET' });
// data is of type string, but should be Blob

As application/pdf is not one of three predefined content types, response is converted to text (in this line).

I know it is impossible to handle all possible content types, but defaulting to text might not be the best idea. Maybe you could add something like customResponseParser, which could be handled in a similar way to customFetch option already provided.

Does this make sense or am I missing something?

@alphanumericaracters
Copy link

Ok, so... now i can/have a response in PDF format and not JSON??? (sorry im newby)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants