DownloadTask.abort(function listener)
Introduction
Abort a download task.
Parameters
function listener
A callback function for the result of the abort
operation.
Parameters
Object res
Attribute | Type | Description |
---|---|---|
success | string | true - successful false - failed |
errCode | string | Error code returned when the operation fails. |
errMsg | string | Error message returned when the operation fails. |
Explanation of errMsg
Error Message | Explanation |
---|---|
Download Abort Fail, callbackId is empty: D009 | Operation failed, download task not found |
Download Abort Fail, "+error+": D011 | Operation failed, exception information |
Download Abort Fail, Exception_" + t.toString() +: D010 | Operation failed, error information |
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.abort((res) => {
console.log(res);
}); // Cancel the download task
},
});