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:
Sven (AAMOS AI)
2026-08-12 20:30:24 +07:00
parent 716e768cd0
commit bf04a12b89
2 changed files with 63 additions and 3 deletions
+3 -3
View File
@@ -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,