Realise-Formation-Digital / 22.02-QrCode-Swiss-Payment

0 stars 0 forks source link

Download the answer from the server #7

Open MarcoTribuz opened 2 years ago

MarcoTribuz commented 2 years ago

Handle the zip file or the pdf file

MarcoTribuz commented 2 years ago

Please note this example

https://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery

fetch('https://jsonplaceholder.typicode.com/todos/1') // already done
  .then(resp => resp.blob()) // already done
  .then(blob => { // already done
    const url = window.URL.createObjectURL(blob); //todo
    const a = document.createElement('a'); //todo
    a.style.display = 'none'; //todo
    a.href = url; //todo
    // the filename you want //todo
    a.download = 'todo-1.json'; //todo
    document.body.appendChild(a); //todo
    a.click(); //todo
    window.URL.revokeObjectURL(url); //todo
  })
  .catch(() => alert('oh no!'));