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
Attribute | Type | Description |
---|---|---|
progress | number | Upload progress in percentage. |
totalBytesWritten | number | The length of data that has been uploaded, in Bytes. |
totalBytesExpectedToWrite | number | The 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);
});
},
});