Skip to content

Netlify Adapter does not return properly formed response for binary data #4174

@bummzack

Description

@bummzack

Describe the bug

In order to return binary data (eg. a generated Image) from a Netlify function, the data must be converted to a base64 encoded string with the proper content-type.

This is done in handler.js, but the condition that checks for Uint8Array will always fail, as the response type changed with #3384

From what I can tell, there is currently no way to determine the "type" from the response, other than looking at the content-type header and using something like is_text

Reproduction

Here's a minimal setup: https://github.com/bummzack/sveltekit-netlify-binary-response

There's twice the same code running in a SvelteKit Endpoint (image.png) and a separate Netlify function.

The SvelteKit endpoint does not encode the image properly and it won't be displayed:
https://elated-knuth-7439db.netlify.app/image.png

The direct implementation as a separate Netlify function works as expected:
https://elated-knuth-7439db.netlify.app/.netlify/functions/test

Logs

No response

System Info

Local system is irrelevant, since the issue doesn't occur locally.

  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.30 
    @sveltejs/kit: next => 1.0.0-next.288 
    svelte: ^3.44.0 => 3.46.4

Severity

annoyance

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedPRs welcomed. The implementation details are unlikely to cause debatep2-nice-to-haveSvelteKit cannot be used by a small number of people, quality of life improvements, etc.pkg:adapter-netlify

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions