HomeDocs
跳到主要内容

UploadTask

简介

一个可以监听上传进度变化事件,以及取消上传任务的对象。

方法

示例代码

// pages/index/index.js

Page({
uploadFile() {
const uploadTask = dlt.uploadFile({
url: "xxx",
filePath: tempFilePaths[0],
name: "file",
formData: {
user: "test",
},
success(res) {
console.log(res);
},
fail(res) {
console.error(res);
},
});

uploadTask.onProgressUpdate((res) => {
console.log("上传进度", res.progress);
console.log("已经上传的数据长度", res.totalBytesWritten);
console.log("预期需要上传的数据总长度", res.totalBytesExpectedToWrite);
});

uploadTask.abort((res) => {
console.log(res);
}); // 取消上传任务
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.