axios下载文件

async function download (url:string,filePath:string) {  
    
    
    const writer = fs.createWriteStream(filePath)
  
    const response = await axios({
      url,
      method: 'GET',
      responseType: 'stream'
    })
  
    response.data.pipe(writer)
  
    return new Promise((resolve, reject) => {
      writer.on('finish', resolve)
      writer.on('error', reject)
    })
  }

你可能感兴趣的:(javascriptaxios)