# DownloadTask wx.downloadFile(Object object)

with Promise style call: Not supported

Mini Program plugin: Support, need to Mini Program base library version no less than 1.9.6

Download file resources to the local. The client directly initiates a HTTPS GET Request, return the local temporary path to the file (Local path)The maximum file allowed for a single download is 200MB。 Please read carefully before usingRelated notes

Note: Please click the header Specifies a reasonable Content-Type Field to ensure that the client handles file types correctly.

# parameter

# Object object

attribute type Default values Required Introductions Minimum version
url string yes Download resource url
header Object no HTTP Requested Header,Header Can not be set Refer
timeout number no Timeout in milliseconds 2.10.0
filePath string no Specify the path to store files after they are downloaded (Local path) 1.8.0
success function no Interface calls the successful callback function
fail function no Interface calls failed callback functions
complete function no Callback function at the end of an interface call (both successful and unsuccessful calls are executed)

# object.success callback

# parameter
# Object res
attribute type Introductions Minimum version
tempFilePath string Temporary file path (Local path)No incoming filePath When you specify a file storage path, the downloaded file is stored in a temporary file
filePath string User File Path (Local path)Incoming. filePath Is returned when the filePath Agreement
statusCode number Returned by the developer server HTTP Status code
profile Object Some debugging information during the network request,View details 2.10.4

res.profile Structure

attribute type Introductions
redirectStart number The first. HTTP The time when the redirection occurred. There is a jump and redirection within the same domain, otherwise the value is 0
redirectEnd number Last one. HTTP Time at which the redirection completes. Redirects within the same domain with a jump, otherwise the value is 0
fetchStart number Components ready to use HTTP Request time to fetch resource, before checking local cache
初始值 number 初始值 初始值 初始值 初始值 fetchStart 初始值
domainLookupEnd number DNS When the domain name query was completed, if local caching was used DNS Query) or persistent connection, with the fetchStart Value equality
connectStart number HTTP(TCP) When a connection is established, and if the connection is persistent, the fetchStart Values are equal. Note that if an error occurs at the transport layer and a connection is reestablished, this shows the time when the newly established connection started
connectEnd number HTTP(TCP) Time to complete the connection establishment (complete handshake), or if the connection is persistent, with the fetchStart Values are equal. Note that if an error occurs at the transport layer and the connection is reestablished, the time when the newly established connection was completed is shown here. Note the end of the handshake, including the establishment of the security connection, SOCKS Authorized by
SSLconnectionStart number Time when the SSL connection was established, or if it is not a secure connection, the value is 0
SSLconnectionEnd number Time when SSL is established, or if it is not a secure connection, the value is 0
requestStart number The time when the HTTP request started reading the real document (complete connection establishment), including reading the cache locally. When the connection is reconnected, the time of the new connection is also shown here
requestEnd number When the HTTP request reads the real document ends
responseStart number HTTP Time to start receiving the response (first byte), including reading the cache locally
responseEnd number HTTP Time when the response is complete (to the last byte), including reading the cache locally
rtt number When a request is connected in real time rtt
estimate_nettype number Network State Assessment unknown, offline, slow 初始值 初始值 3g, 4g, 初始值/初始值 1, 2, 3, 4, 5, 6
httpRttEstimate number The protocol layer evaluates the current network's Rtt (for reference only)
transportRttEstimate number Of the current network evaluated by the transport layer based on multiple requests Rtt (for reference only)
downstreamThroughputKbpsEstimate number Evaluate kbps for current network downloads
throughputKbps number Actual downloads from the current network kbps
peerIP string IP currently requested
port number Port currently requested
socketReused boolean Reusing connections
sendBytesCount number Number of bytes sent
receivedBytedCount number Number of bytes received
protocol string Using protocol type, valid value: http 1.1, h2, quic, unknown

# Return value

# DownloadTask

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

An object that can listen for download progress changes and cancel downloads

# sample code

  url: 'https://example.with/audio/123', //Just an example, not a real resource.
  success (res) {
    // As long as the server has the response data, the response will be written to a file and entered success Callback, the business needs to determine whether to download the desired content
    if (res.statusCode === 200) {
        filePath: res.tempFilePath