UploadTask.offProgressUpdate

基础库 3.180.1 版本开始支持。

解释:取消监听下载进度变化。

方法参数

Function callback

示例

代码示例

  • SWAN
  • JS
  1. <view>
  2. <button type="primary" bindtap="offProgressUpdate">取消下载进度变化的监听</button>
  3. </view>
  1. Page({
  2. offProgressUpdate() {
  3. swan.chooseImage({
  4. success: res => {
  5. let uploadTask = swan.uploadFile({
  6. //开发者服务器 url
  7. url: 'https://smartprogram.baidu.com/xxx',
  8. // 要上传文件资源的路径
  9. filePath: res.tempFilePaths[0],
  10. name: 'myfile',
  11. header: {
  12. 'content-type': 'application/json'
  13. },
  14. formData: {
  15. 'user': 'swan'
  16. },
  17. success: () =>{
  18. console.log('uploadFile success');
  19. },
  20. fail: err => {
  21. console.log('uploadFile fail');
  22. }
  23. });
  24. let cb = res => {
  25. swan.showModal({
  26. title: 'onProgressUpdate',
  27. content: JSON.stringify(res)
  28. });
  29. // 不传递 cb 将删除此对象上所有上传进度变化事件的回调函数
  30. uploadTask.offProgressUpdate();
  31. };
  32. uploadTask.onProgressUpdate(cb);
  33. }
  34. })
  35. }
  36. });