Cannot rewrite cURL to JavaScript

Description

I’m trying to rewrite this here https://docs.rocket.chat/api/rest-api/methods/rooms/upload in pure JavaScript

curl "http://localhost:3000/api/v1/rooms.upload/GENERAL" \
    -F file=@$HOME/example.txt \
    -H "X-Auth-Token: ijFlJ1yfidXhwEYY284Anoq_iEsOeMMVCupzNhX22tB" \
    -H "X-User-Id: hw5DThnhQmxDWnavu"

but I get a bad-request error 400 with the JavaScript equivalent whereas the cURL command works.

That is my JavaScript equivalent:

var xhr = new XMLHttpRequest();
xhr.open("POST", 'http://localhost:3000/api/v1/rooms.upload/GENERAL', true);

const formData = new FormData();
formData.append("upload", file);  // file has type File https://www.javascripture.com/File

xhr.setRequestHeader("Content-Type", "multipart/form-data");
xhr.setRequestHeader("X-Auth-Token", "ijFlJ1yfidXhwEYY284Anoq_iEsOeMMVCupzNhX22tB");
xhr.setRequestHeader("X-User-Id", "hw5DThnhQmxDWnavu");
xhr.send(formData);

See here for cURL documentation of the parameter F https://curl.haxx.se/docs/manpage.html#-F
Have somebody an idea why it does not work?