# DownloadTask

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

Listens on the download progress change event and cancels download tasks.

# Methods

# DownloadTask.abort()

Aborts download tasks.

# DownloadTask.onProgressUpdate(function callback)

Listens on the download progress change event.

# DownloadTask.offProgressUpdate(function callback)

Un-listens on download progress change events.

# DownloadTask.onHeadersReceived(function callback)

Listens on HTTP Response Header event, which will be earlier than the request completion event.

# DownloadTask.offHeadersReceived(function callback)

Un-listens on the HTTP Response Header event.

# Sample Code

const downloadTask = wx.downloadFile({
  url: 'http://example.com/audio/123', //This value for demonstration purposes only is not a real resource.
  success (res) {
    wx.playVoice({
      filePath: res.tempFilePath
    })
  }
})

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

downloadTask.abort() //Cancel download tasks