From 9bfbd63f05d21b51f7fd726fc4c16949919529a0 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Tue, 20 Sep 2022 15:33:01 -0400 Subject: [PATCH] Fixes processing of images in Netlify functions (#4820) --- .changeset/khaki-trainers-cheat.md | 5 +++++ .../integrations/netlify/src/netlify-functions.ts | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .changeset/khaki-trainers-cheat.md diff --git a/.changeset/khaki-trainers-cheat.md b/.changeset/khaki-trainers-cheat.md new file mode 100644 index 000000000..4751c5817 --- /dev/null +++ b/.changeset/khaki-trainers-cheat.md @@ -0,0 +1,5 @@ +--- +'@astrojs/netlify': patch +--- + +Fix processing of images in Netlify Functions diff --git a/packages/integrations/netlify/src/netlify-functions.ts b/packages/integrations/netlify/src/netlify-functions.ts index d40254f96..c6b253b0d 100644 --- a/packages/integrations/netlify/src/netlify-functions.ts +++ b/packages/integrations/netlify/src/netlify-functions.ts @@ -36,6 +36,7 @@ export const createExports = (manifest: SSRManifest, args: Args) => { 'image/bmp', 'image/gif', 'image/vnd.microsoft.icon', + 'image/heif', 'image/jpeg', 'image/png', 'image/svg+xml', @@ -84,9 +85,13 @@ export const createExports = (manifest: SSRManifest, args: Args) => { const responseContentType = parseContentType(responseHeaders['content-type']); const responseIsBase64Encoded = knownBinaryMediaTypes.has(responseContentType); - const responseBody = responseIsBase64Encoded - ? Buffer.from(await response.text(), 'binary').toString('base64') - : await response.text(); + let responseBody: string; + if(responseIsBase64Encoded) { + const ab = await response.arrayBuffer(); + responseBody = Buffer.from(ab).toString('base64'); + } else { + responseBody = await response.text(); + } const fnResponse: any = { statusCode: response.status,