Skip to content

Commit

Permalink
fix(client): correct File construction from node-fetch Responses (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Sep 3, 2024
1 parent 3c7bdfd commit 22ebdc2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 22ebdc2

Please sign in to comment.