showing results for - "react axios download zip file"
Emily
02 Sep 2018
1
2export function someFunction(values) {
3
4  return (dispatch) => {
5
6    ...
7
8    const method = 'GET';
9
10    const url = 'http://go.api/download_file';
11
12    ...
13
14    axios
15
16      .request({
17
18        url,
19
20        method,
21
22        responseType: 'blob', //important
23
24      })
25
26      .then(({ data }) => {
27
28        const downloadUrl = window.URL.createObjectURL(new Blob([data]));
29
30        const link = document.createElement('a');
31
32        link.href = downloadUrl;
33
34        link.setAttribute('download', 'file.zip'); //any other extension
35
36        document.body.appendChild(link);
37
38        link.click();
39
40        link.remove();
41
42      });
43
44  };
45
46}
47
48