-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Netlify Adapter does not return properly formed response for binary data #4174
Comments
Sorry, I wanted to create a PR for this, but I banged my head against the keyboard while trying to understand how I could import I guess it somehow needs to be exported from |
I'm having the same problem on Netlify when trying to serve out a dynamically generated PDF. Works fine locally. I tried to create a PR for the This does look like it should be a relatively simple thing to fix for anyone that knows what they are doing (unlike myself!). I will run a custom netlify function in the meantime as a workaround. |
* base64-encode binary responses - closes #4174 * tweak comments
Thanks @Rich-Harris ❤️ |
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 forUint8Array
will always fail, as the response type changed with #3384From 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 likeis_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
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: