You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Object.prototype.toString.call(form) returns "[object Object]" instead of "[object FormData]" #396
This appears to be due to a change in the algorithm used for determining the toString of an Object. See step 16 of 19.1.3.6 Object.prototype.toString ( )
constform=newFormData();assert(form.toString()=="[object FormData]","toString() results in [object FormData]")assert(Object.prototype.toString.call(form)=="[object FormData]","Object.prototype.toString.call(form) results in [object FormData]")
In version 2.3.2 of FormData, the second assertion will fail as Object.prototype.toString.call(form) returns [object Object]
The fix for this is to add support for the toStringTag symbol, like the following:
Activity
henryozoebuka commentedon Feb 12, 2025
ljharb commentedon Feb 12, 2025
ThisIsMissEm commentedon Feb 12, 2025
henryozoebuka commentedon Feb 13, 2025
ljharb commentedon Feb 13, 2025
[Fix] set `Symbol.toStringTag` when available
[Fix] set `Symbol.toStringTag` when available
[Fix] set `Symbol.toStringTag` when available (#573)
[Fix] set `Symbol.toStringTag` when available (#573)
ljharb commentedon Feb 14, 2025
Released in v4.0.2 and backported to v3.0.3 and v2.5.3.
engPabloMartinez commentedon Nov 17, 2025
I can still see this same behaviour on 4.04
ljharb commentedon Nov 17, 2025
@engPabloMartinez on which engine?
form-data/lib/form_data.js
Line 491 in 16e0076
engPabloMartinez commentedon Nov 17, 2025
I am seeing this in a NextJS application on the server side, so NodeJS.
const formData = new FormData();
formData.append('file', fs.createReadStream(
/tmp/${fileName}));formData.append(
'type',
mimeType === 'image/jpg' ? 'image/jpeg' : mimeType
);
console.log('Prototype: ', Object.prototype.toString.call(formData));
console.log('toString: ', formData.toString());
And I get
Prototype: [object Object]
toString: [object FormData]
ljharb commentedon Nov 17, 2025
Thanks, I've reproduced it and will have a fix out shortly.
[Fix] set Symbol.toStringTag in the proper place
ljharb commentedon Nov 17, 2025
v4.0.5 is released.
engPabloMartinez commentedon Nov 17, 2025
Thanks, now it is working.