Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): correct File construction from node-fetch Responses #1029

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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