fix(gemini): read binary response body as Buffer instead of UTF-8 string
customNodeFetch previously used res.setEncoding('utf8') and concatenated
chunks into a string. This corrupted JPEG/PNG binary data with UTF-8
replacement characters, causing Gemini to return:
400 Unable to process input image.
Now chunks are collected as Buffers and concatenated, preserving binary
integrity when images are fetched from presigned S3 URLs before being
sent to Gemini.
This commit is contained in:
@@ -76,10 +76,10 @@ function requestOnce(input: string | URL | Request, init: RequestInit | undefine
|
||||
return;
|
||||
}
|
||||
|
||||
let body = "";
|
||||
res.setEncoding("utf8");
|
||||
res.on("data", (chunk) => { body += chunk; });
|
||||
const chunks: Buffer[] = [];
|
||||
res.on("data", (chunk: Buffer) => { chunks.push(chunk); });
|
||||
res.on("end", () => {
|
||||
const body = Buffer.concat(chunks);
|
||||
resolve(
|
||||
new Response(body, {
|
||||
status,
|
||||
|
||||
Reference in New Issue
Block a user