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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import axios from 'axios';
const instance = axios.create();
export const apiUrl = '/';
const token = localStorage.getItem("token");
let defaultHeaders = {
token,
};
const createAPI = (baseURL) => {
return (conf = {}) => {
let opts = conf.opts || {};
let headers = { ...defaultHeaders, ...opts.headers };
return instance(Object.assign({}, {
url: conf.url,
baseURL: baseURL,
params: conf.opts,
method: conf.method,
data: conf.payload || null,
headers,
responseType: 'blob',
}))
.then(function (response) {
return response
})
.catch(error => {
return false;
});
};
}
const instance2 = createAPI(apiUrl);
async function downloadFile(option = {}) {
return await instance2({
method: option.method || 'get',
url: option.url,
opts: option.body || null,
});
}
export default downloadFile;