Skip to content

Commit

Permalink
fix(client): correct File construction from node-fetch Responses (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Nov 1, 2024
1 parent edc34d0 commit 42a63ac
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 42a63ac

Please sign in to comment.