Starting from version 1078, the API prefix has been changed from hbs to qg. The original prefix hbs is still supported.
API | Description |
|---|---|
Downloads a file to a local path. | |
Suspends a download task. | |
Listens for download progress change events. |
Downloads a file to a local path. The client directly initiates an HTTPS GET request and obtains the local temporary path for storing the file through a callback function. A DownloadTask object is returned.
If no download path is specified, files larger than 50 MB can be downloaded to the local device using a temporary file path.
Parameter | Type | Mandatory | Description |
|---|---|---|---|
url | string | Yes | URL of the file to be downloaded. |
header | object | No | Header of an HTTP request. The header cannot contain a referer. |
filePath | string | No | Path for saving the downloaded file, including the file name.
|
success | function | No | Callback function triggered upon a successful API call. |
fail | function | No | Callback function triggered upon a failed API call. |
complete | function | No | If a function is passed, it will be called regardless of whether the API call succeeds or fails. |
Parameter | Type | Description |
|---|---|---|
tempFilePath | string | Temporary file path (local path). This parameter is returned when the file storage path specified by filePath is not passed. In this case, the downloaded file is stored in the temporary path. |
filePath | string | User file path (local path). This parameter is returned when filePath is passed. The value is the same as that of filePath. |
statusCode | number | HTTP status code returned by your server. |
qg.downloadFile({
url: "http://127.0.0.1:8080/docs/test.zip",
filePath:qg.env.USER_DATA_PATH +"/sdcard/Pictures/Screenshots/test.zip",
success() {
console.log("success");
},
fail(e) {
console.error(e.errMsg);
},
complete() {
console.log("complete");
}
}); Parameter | Type | Mandatory | Description |
|---|---|---|---|
callback | function | Yes | Callback function for download progress change events. |
Parameter | Type | Description |
|---|---|---|
progress | number | Download progress, in percentage. |
totalBytesWritten | number | Size of the downloaded data, in bytes. |
totalBytesExpectedToWrite | number | Anticipated total size of data to be downloaded, in bytes. |
var downloadTask = qg.downloadFile({
url : 'url'
});
downloadTask.onProgressUpdate(
callback(res){console.log("onProgressUpdate result = " + JSON.stringify(res));}
)