From 3781c35e2c34ff43b01b26c6d9d2793919ee7743 Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 12:40:03 +0000 Subject: [PATCH] fix(client): correct File construction from node-fetch Responses (#1029) --- src/uploads.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/uploads.ts b/src/uploads.ts index 081827c9a..a920351cd 100644 --- a/src/uploads.ts +++ b/src/uploads.ts @@ -114,7 +114,12 @@ export async function toFile( const blob = await value.blob(); name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file'; - return new File([blob as any], name, options); + // we need to convert the `Blob` into an array buffer because the `Blob` class + // that `node-fetch` defines is incompatible with the web standard which results + // in `new File` interpreting it as a string instead of binary data. + const data = isBlobLike(blob) ? [(await blob.arrayBuffer()) as any] : [blob]; + + return new File(data, name, options); } const bits = await getBytes(value);