HomeDocs
Skip to main content

UploadTask

Introduction

An object that can listen for changes in upload progress and cancel upload tasks.

Methods

Sample Code

// 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("Upload progress", res.progress);
console.log("Uploaded data length", res.totalBytesWritten);
console.log("Total expected data length to upload", res.totalBytesExpectedToWrite);
});

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