Attribute | Type | Required | Description |
url | string | Yes | URL for resource download |
header | Object | No | HTTP request's Header; setting Referer within the Header is not allowed. |
timeout | number | No | Timeout duration, measured in milliseconds (ms). |
filePath | string | No | Designated path for storing the downloaded files |
success | function | No | Callback Function of Successful Interface Call |
fail | function | No | Callback Function of Failing Interface Call |
complete | function | No | Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations) |
Attribute | Type | Description |
tempFilePath | string | Temporary file path (local path). If no filePath is specified for file storage, this will be returned. The downloaded files will be stored in a temporary folder. |
filePath | string | User file path (local path). This will be returned when a filePath is passed in, and it will be consistent with the provided filePath. |
statusCode | number | HTTP status code returned from the developer's server. |
profile | Object | Some debugging information during the network request process. |
Structure attributes | Type | Description |
redirectStart | number | The time of the first HTTP redirect. This is only applicable for redirects within the same domain. Otherwise the value is 0. |
redirectEnd | number | The time of completing the last HTTP redirect. This is only applicable for internal redirects within the same domain. Otherwise the value is 0. |
fetchStart | number | The time at which the component is ready to fetch resources using an HTTP request, occurring prior to the inspection of the local cache. |
domainLookupStart
| number | The time at which the DNS domain name query begins. If the local cache is used (i.e., no DNS query) or a persistent connection is established, it is equivalent to the fetchStart value. |
domainLookupEnd | number | The time at which the DNS domain name query completes. If the local cache is used (i.e., no DNS query) or a persistent connection is established, it is equivalent to the fetchStart value. |
connectStart | number | The time at which the HTTP (TCP) connection begins to establish. If a persistent connection is in place, it is equivalent to the fetchStart value. |
connectEnd | number | The time at which the HTTP (TCP) connection is fully established (handshake completed). If a persistent connection is in place, it is equivalent to the fetchStart value. Note that if an error occurs at the transport layer and the connection is reestablished, the time displayed here is the completion of the newly established connection. |
SSLconnectionStart | number | The time at which the SSL connection is established. If it is not a secure connection, the value is 0. |
SSLconnectionEnd | number | The time at which the SSL establishment is completed. If it is not a secure connection, the value is 0. |
requestStart | number | The time at which the HTTP request begins to read the actual document (completion of connection establishment), including reading from the local cache. In the event of a connection error and reconnection, the time displayed here is the time of the newly established connection. |
requestEnd | number | The time at which the HTTP request finishes reading the actual document. |
responseStart | number | The time at which the HTTP begins to receive the response (upon receiving the first byte), including reading from the local cache. |
responseEnd | number | The time at which the HTTP response is fully received (upon receiving the last byte), including reading from the local cache. |
rtt | number | The real-time round-trip time (rtt) during the connection process of the current request. |
estimate_nettype | number | Assessed network status: unknown, offline, slow 2G, 2G, 3G, 4G, last/0, 1, 2, 3, 4, 5, 6. |
httpRttEstimate | number | The protocol layer assesses the current network's round-trip time (rtt) based on multiple requests (for reference only). |
transportRttEstimate | number | The protocol layer assesses the current network's round-trip time (rtt) based on multiple requests (for reference only). |
downstreamThroughputKbpsEstimate | number | Assess the kilobits per second (kbps) of the current network download. |
throughputKbps | number | The actual download kilobits per second (kbps) of the current network. |
peerIP | string | IP of the current request. |
port | number | Port of the current request |
socketReused | boolean | Whether to reuse the connection. |
sendBytesCount | number | The number of bytes transmitted |
receivedBytedCount | number | The number of bytes received |
protocol | string | Protocol type in use, with valid values: http1.1, h2, quic, unknown. |
wx.downloadFile({url: 'https://example.com/audio/123', // This is merely an example, not an actual resource.success (res) {// As long as the server has response data, the response content will be written into the file and enter the success callback. It is up to the business side to determine whether the desired content has been downloaded.if (res.statusCode === 200) {wx.playVoice({filePath: res.tempFilePath})}}})
This method is used via DownloadTask.abort().
This method is used via DownloadTask.onProgressUpdate(function listener).
Attribute | Type | Description |
progress | number | Download progress percentage |
totalBytesWritten | number | Length of the data already downloaded, measured in Bytes. |
totalBytesExpectedToWrite | number | Total length of the data expected to be downloaded, measured in bytes. |
This method is used via DownloadTask.offProgressUpdate(function listener).
const listener = function (res) { console.log(res) }DownloadTask.onHeadersReceived(listener)DownloadTask.offHeadersReceived(listener) // The same function object as the listener must be passed in.
This method is used via DownloadTask.onHeadersReceived(function listener).
Attribute | Type | Description |
header | Object | HTTP Response Header returned from the developer's server. |
This method is used via DownloadTask.offHeadersReceived(function listener).
const listener = function (res) { console.log(res) }DownloadTask.onHeadersReceived(listener)DownloadTask.offHeadersReceived(listener) // The same function object as the listener must be passed in.
const downloadTask = wx.downloadFile({url: 'http://example.com/audio/123', // This is merely an example, not an actual 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(''Length of data expected to be downloaded', res.totalBytesExpectedToWrite)})downloadTask.abort() // Aborts the download task
Was this page helpful?