File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) ) ;
You can’t perform that action at this time.
0 commit comments