Confluence (server version) - upload attachment in pure Javascript

In the HTML macro on a confluence page, I managed to get data from an attached excel file in a javascript variable. I could then do all sorts of manipulation. However, I did not manage to upload the processed file back to the attachments. Here is what I did already:

<script src=""></script>
var xldata; var workbook; var firstSheet; var result; var fresult=[]; var wb; var ws; var outData;
var url2="";
var request2 = new XMLHttpRequest();  
request2.responseType = "arraybuffer";"GET", url2, true);   
request2.onload = function() {xldata = new Uint8Array(request2.response);}

With the javascript from the XLSX library, I could turn this into a new excel file.

  // read the data from xldata into an XLSX object
  workbook = , {type: 'array'});
  // get a handle to the first sheet
  firstSheet = workbook.Sheets[workbook.SheetNames[0]];
  // put the data of the first sheet into a javascript variable result
  result = XLSX.utils.sheet_to_json(firstSheet, { header: 1 });
  //put the array into a structure (given the first row was a HEADER row)
  result.forEach(function(row,i){if (i>0){var trow={}; row.forEach(function(elm,j){trow[result[0][j]]=elm});fresult.push(trow)}});

  //create a new workbook
  // create a new worksheet into the workbook and append a sheet
	document.getElementById("landen").innerHTML="fresult: \n"+JSON.stringify(fresult);

So far so good, everything is working as expected!
There are two ways I can turn that workbook object into a file

 // create variable with the "file" data
 var outData = XLSX.write(wb, {bookType:'xlsx',  type: 'binary'});
 // or create a BLOB (that is automatically downloaded). 
 var data = XLSX.writeFile(wb, "nnew.xlsx");

The downloaded file is exactly what I expect it to be. A new excel book with the same data.
I would want to have this now - in pure javascript - uploaded to the attachments.
Here is what I tried.

var path=""
var request3 = new XMLHttpRequest();"POST",path,true);
request3.setRequestHeader("X-Atlassian-Token", "nocheck");

Then I get the error
XHR failed loading: POST “https://…/child/attachment”
POST “https://…/child/attachment” net::ERR_CONNECTION_TIMED_OUT

I have no idea what I do wrong…