HomeDocs
Skip to main content

UploadTask.onProgressUpdate(function listener)

Introduction

Listen to upload progress change events.

Parameters

function listener

The listener function for upload progress change events.

Parameters

Object res

AttributeTypeDescription
progressnumberUpload progress in percentage.
totalBytesWrittennumberThe length of data that has been uploaded, in Bytes.
totalBytesExpectedToWritenumberThe total length of data expected to be uploaded, in Bytes.

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("Data length already uploaded:", res.totalBytesWritten);
console.log("Total expected data length to upload:", res.totalBytesExpectedToWrite);
});
},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.