Fixes processing of images in Netlify functions (#4820)
This commit is contained in:
parent
a08b178cdb
commit
9bfbd63f05
2 changed files with 13 additions and 3 deletions
5
.changeset/khaki-trainers-cheat.md
Normal file
5
.changeset/khaki-trainers-cheat.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'@astrojs/netlify': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix processing of images in Netlify Functions
|
|
@ -36,6 +36,7 @@ export const createExports = (manifest: SSRManifest, args: Args) => {
|
||||||
'image/bmp',
|
'image/bmp',
|
||||||
'image/gif',
|
'image/gif',
|
||||||
'image/vnd.microsoft.icon',
|
'image/vnd.microsoft.icon',
|
||||||
|
'image/heif',
|
||||||
'image/jpeg',
|
'image/jpeg',
|
||||||
'image/png',
|
'image/png',
|
||||||
'image/svg+xml',
|
'image/svg+xml',
|
||||||
|
@ -84,9 +85,13 @@ export const createExports = (manifest: SSRManifest, args: Args) => {
|
||||||
const responseContentType = parseContentType(responseHeaders['content-type']);
|
const responseContentType = parseContentType(responseHeaders['content-type']);
|
||||||
const responseIsBase64Encoded = knownBinaryMediaTypes.has(responseContentType);
|
const responseIsBase64Encoded = knownBinaryMediaTypes.has(responseContentType);
|
||||||
|
|
||||||
const responseBody = responseIsBase64Encoded
|
let responseBody: string;
|
||||||
? Buffer.from(await response.text(), 'binary').toString('base64')
|
if(responseIsBase64Encoded) {
|
||||||
: await response.text();
|
const ab = await response.arrayBuffer();
|
||||||
|
responseBody = Buffer.from(ab).toString('base64');
|
||||||
|
} else {
|
||||||
|
responseBody = await response.text();
|
||||||
|
}
|
||||||
|
|
||||||
const fnResponse: any = {
|
const fnResponse: any = {
|
||||||
statusCode: response.status,
|
statusCode: response.status,
|
||||||
|
|
Loading…
Reference in a new issue