axios method post url path-to-file responseType blob data you-data if

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
axios(
{
method: 'post',
url: '<path-to-file>',
responseType: 'blob',
data: {
<you-data(if you need)>
}
}
)
.then((response) => {
const a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
const fileName = '<file-name>';
const file = new Blob([response.data], {type: '<file-type>'});
a.href = URL.createObjectURL(file);
a.download = `${fileName}.<file-extension>`;
a.target = '_blank';
a.click();
URL.revokeObjectURL(a.href);
},
(error) => {
console.error(error);
})