Skip to content

Commit c066a2a

Browse files
kadamwhiteclaude
andcommitted
Merge fix: FormData filename coercion on Node 18-22
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2 parents fff9fce + 747a8ee commit c066a2a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

fetch/fetch-transport.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,18 @@ const createUploadForm = async (
205205
}
206206

207207
const form = new FormData();
208-
// An undefined name is treated as omitted: File attachments keep their own name.
208+
// An undefined name must be genuinely omitted, not passed as an explicit third
209+
// argument: FormData coerces a present-but-undefined filename to the string
210+
// "undefined" on Node 18-22, clobbering a File attachment's own name. (Node 24+
211+
// treats a trailing undefined as absent, which masked this in local dev.)
209212
// Cast: by this point `file` is always a Blob at runtime (the `string` and
210213
// `Buffer` cases above always reassign it to one), but TS can't prove the
211214
// `globalThis.Buffer &&`-guarded branch always narrows away `Buffer`.
212-
form.append( 'file', file as Blob, name );
215+
if ( name === undefined ) {
216+
form.append( 'file', file as Blob );
217+
} else {
218+
form.append( 'file', file as Blob, name );
219+
}
213220
// Cast: form field values are arbitrary caller-supplied data, but FormData's
214221
// global (DOM) typing only accepts strings or Blobs.
215222
Object.keys( data ).forEach( key => form.append( key, data[ key ] as string | Blob ) );

0 commit comments

Comments
 (0)