1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
var download = async (url, dir) => {
if (url.length < 1) {
return
}
const fileName = dir + '/' + url.split('/').slice(-1)[0]
console.log("downlaod=>", url, fileName)
try {
const res = await axios.get(url, {
responseType: 'arraybuffer', // 特别注意,需要加上此参数
});
return fs.writeFileSync(fileName, res.data);
} catch (error) {
console.log(error)
}
};
|