DownloadTask.onProgressUpdate(function listener)
Introduction
Listen to download progress change events.
Parameters
function listener
The listener function for download progress change events.
Parameters
Object res
Attribute | Type | Description |
---|---|---|
progress | number | Download progress in percentage. |
totalBytesWritten | number | The length of data that has been downloaded, in Bytes. |
totalBytesExpectedToWrite | number | The total length of data expected to be downloaded, in Bytes. |
Sample Code
// pages/index/index.js
Page({
downloadFile() {
const downloadFileTask = dlt.downloadFile({
url: "xxx",
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});
downloadFileTask.onProgressUpdate((res) => {
console.log("Download Progress:", res.progress);
console.log("Data length already downloaded:", res.totalBytesWritten);
console.log("Total expected data length to download:", res.totalBytesExpectedToWrite);
});
},
});