HomeDocs
Skip to main content

DownloadTask

Introduction

An object that can listen to download progress events and cancel download tasks.

Methods

Sample Code

// pages/index/index.js

Page({
downloadFile() {
const downloadTask = dlt.downloadFile({
url: "xxx",
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});

downloadTask.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);
});

downloadTask.abort((res) => {
console.log(res);
}); // Cancel the download task
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.