File downloading

This commit is contained in:
Magnus Åhall 2023-06-22 17:42:34 +02:00
parent 86cedf9531
commit eaf5e2fb95
3 changed files with 14 additions and 8 deletions

View file

@ -326,14 +326,15 @@ class Node {
}),
})
.then(response=>{
console.log(...response.headers);
let match = response.headers.get('content-disposition').match(/filename="([^"]*)"/)
fname = match[1]
return response.blob()
})
.then(blob=>{
let url = window.URL.createObjectURL(blob)
let a = document.createElement('a');
a.href = url;
a.download = "filename.xlsx";
a.download = fname;
document.body.appendChild(a); // we need to append the element to the dom -> otherwise it will not work in firefox
a.click();
a.remove(); //afterwards we remove the element again