Cannot rewrite cURL to JavaScript


I’m trying to rewrite this here 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();"POST", 'http://localhost:3000/api/v1/rooms.upload/GENERAL', true);

const formData = new FormData();
formData.append("upload", file);  // file has type File

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

See here for cURL documentation of the parameter F
Have somebody an idea why it does not work?