Advertisement
Guest User

axios

a guest
Feb 11th, 2021
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             downloadFile(fileId) {
  2.             axios({
  3.                 url: 'http://localhost:8081/download?fileId=' + fileId,
  4.                 method: 'GET',
  5.                 responseType: 'blob',
  6.                 headers: {
  7.                     Authorization: 'Basic ' + localStorage.getItem('user')
  8.                 }}).then((response) => {
  9.                 const url = window.URL.createObjectURL(new Blob([response.data]));
  10.                 const link = document.createElement('a');
  11.                 link.href = url;
  12.                 link.setAttribute('download', 'file.pdf'); //or any other extension
  13.                 document.body.appendChild(link);
  14.                 link.click();
  15.                 });
  16.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement