Skip to content

Commit

Permalink
Fixes processing of images in Netlify functions (#4820)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Sep 20, 2022
1 parent a08b178 commit 9bfbd63
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-trainers-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---

Fix processing of images in Netlify Functions
11 changes: 8 additions & 3 deletions packages/integrations/netlify/src/netlify-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 9bfbd63

Please sign in to comment.