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 Sep 3, 2024
1 parent 78ee259 commit 3781c35
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 3781c35

Please sign in to comment.