Here it is for the sake of next generations:
function uploadfile(flname,data)
{
var boundary = "----WebKitFormBoundarygqk86ALR3dpFbAaF";
var xhr = new XMLHttpRequest();
var body = '--'+ boundary + '\r\n'+'Content-Disposition: form-data; name="MAX_FILE_SIZE"\r\n\r\n100000\r\n'+'--' + boundary +'\r\n'+'Content-Disposition: form-data; name="uploadedfile";'+ 'filename="'+flname+'.xml"\r\n'+ 'Content-Type: text/xml\r\n\r\n'+ data + '\r\n'+ '--'+boundary + '--\r\n';
xhr.open("POST", "/edit", true);
xhr.setRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" );
xhr.setRequestHeader(
"Content-Type", "multipart/form-data; boundary="+boundary
);
xhr.onreadystatechange = function ()
{
if (xhr.readyState == 4 && xhr.status == 200)
alert("File uploaded!"+xhr.responseText);
}
xhr.send(body);
}
The function takes two variables - flname is the filename without extention - I've added '.xml' in my code. The data var is the content of the file to be uploaded.
If anybody wonders, the Boundary variable is just a random string used to delineate the block into parts.
The rest of it is quite straightforward (once it works).