Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 22ebdc2

Browse files
stainless-app[bot]stainless-bot
authored andcommittedSep 3, 2024·
fix(client): correct File construction from node-fetch Responses (#1029)
1 parent 3c7bdfd commit 22ebdc2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed
 

‎src/uploads.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,12 @@ export async function toFile(
114114
const blob = await value.blob();
115115
name ||= new URL(value.url).pathname.split(/[\\/]/).pop() ?? 'unknown_file';
116116

117-
return new File([blob as any], name, options);
117+
// we need to convert the `Blob` into an array buffer because the `Blob` class
118+
// that `node-fetch` defines is incompatible with the web standard which results
119+
// in `new File` interpreting it as a string instead of binary data.
120+
const data = isBlobLike(blob) ? [(await blob.arrayBuffer()) as any] : [blob];
121+
122+
return new File(data, name, options);
118123
}
119124

120125
const bits = await getBytes(value);

0 commit comments

Comments
 (0)
Please sign in to comment.