# DownloadTask

Start from base library version 1.4.0. Please remaining backward compatible.

An object that can listen for changes in download progress and cancel the download task

# method

# DownloadTask.abort()

Interrupt Download Task

# DownloadTask.onProgressUpdate(function callback)

Listen for changes in download progress

# DownloadTask.offProgressUpdate(function callback)

Cancel listening for download schedule change events

# DownloadTask.onHeadersReceived(function callback)

to monitor HTTP Response Header Events. Will be earlier than the request to complete the event

# DownloadTask.offHeadersReceived(function callback)

Cancel the wiretap. HTTP Response Header event

# sample code

const downloadTask = wx.downloadFile({
  url: 'http://example.with/audio/123', //Just an example, not a real resource.
  success (res) {
    wx.playVoice({
      filePath: res.tempFilePath
    })
  }
})

downloadTask.onProgressUpdate((res) => {
  console.log("Download progress"? res.progress)
  console.log('length of data already downloaded ', res.totalBytesWritten)
  console.log(Total length of data expected to be downloaded, res.totalBytesExpectedToWrite)
})

downloadTask.abort() // Cancel the download task