dlt.downloadFile
Introduction
Download file resources to the local system. The client initiates an HTTPS GET request directly, which returns the file's local temporary path (local path).
Parameters
Object object
Property | Type | Default | Required | Description | Minimum Version |
---|---|---|---|---|---|
url | string | Yes | The address to request. | ||
saveName | string | No | It can be empty. If it is empty, the string after the last delimiter in the URL is taken. | ||
header | string | No | Set the request header as a JSON string. | ||
timeout | number | 60000 | No | Timeout in milliseconds. The default value is 60000. | Supported since version 3.0.0 |
success | function | No | A callback function that will be called when the interface is successfully invoked. | ||
fail | function | No | A callback function that will be called when the interface is unsuccessfully invoked. | ||
complete | function | No | A callback function that will be called when the interface call ends (whether it is successful or not). |
Callback Function object.success
Parameters
Object res
Attribute | Type | Description |
---|---|---|
tempFilePath | string | The temporary download path. |
success | string | true - successful setting. |
Callback Function object.fail
Parameters
Object res
Attribute | Type | Description |
---|---|---|
errCode | string | Error code. |
errMsg | string | Error message. |
success | string | false - setting failed. |
Explanation of errMsg
Error Message | Explanation |
---|---|
Download Fail, Data storage failed because of insufficient storage space: S001 | Download failed, insufficient storage space. |
Download Fail, Exception_" + t.toString() +: D002 | Download failed: Exception occurred. |
Download Fail, appId is empty: D003 | Download failed: App ID does not exist. |
Download Fail, downloadUrl is error: D004 | Download failed: Invalid download address. |
Download Fail, downloadPath is empty: D005 | Download failed: Download storage path is empty. |
Download Fail, onFailure_" + e.toString() +: D006 | Download failed. |
Download Fail, onResponse_" + e.toString() +: D007 | Download failed. |
Sample Code
// pages/index/index.js
Page({
downloadFile() {
dlt.downloadFile({
url: "xxx",
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
},
});