# UploadTask

更新时间:2024-07-23 11:06:59

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

# 方法

# UploadTask.abort()

中断上传任务

# UploadTask.onProgressUpdate(function callback)

监听上传进度变化事件

# UploadTask.offProgressUpdate(function callback)

取消监听上传进度变化事件

# 示例代码

const uploadTask = ks.uploadFile({  
  url: 'http://example.kuaishou.com/upload', //仅为示例,非真实的接口地址  
  filePath: tempFilePaths[0],  
  name: 'file',  
  formData:{  
    'user': 'test'  
  },  
  success (res){  
    const data = res.data  
    //do something  
  }  
})  
  
uploadTask.onProgressUpdate((res) => {  
  console.log('上传进度', res.progress)  
  console.log('已经上传的数据长度', res.totalBytesSent)  
  console.log('预期需要上传的数据总长度', res.totalBytesExpectedToSend)  
})  
  
uploadTask.abort() // 取消上传任务  
Copyright ©2025, All Rights Reserved