UploadTask.abort

解释:中断上传任务

方法参数

示例

在开发者工具中预览效果

扫码体验

UploadTask.abort - 图1请使用百度APP扫码

图片示例

UploadTask.abort - 图2

UploadTask.abort - 图3

UploadTask.abort - 图4

代码示例

  1. Page({
  2. data: { },
  3. uploadFile() {
  4. swan.chooseImage({
  5. success: res => {
  6. const uploadTask = swan.uploadFile({
  7. url: 'https://smartprogram.baidu.com/mappconsole/api/checkFile',
  8. filePath: res.tempFilePaths[0],
  9. name: 'myfile',
  10. header: {
  11. 'content-type': 'application/json'
  12. },
  13. formData: {
  14. 'user': 'swan'
  15. },
  16. success: res => {
  17. swan.showModal({
  18. title: 'title',
  19. content: "上传成功"
  20. });
  21. console.log('uploadFile success', res);
  22. this.setData({filePath});
  23. },
  24. fail: err => {
  25. console.log('uploadFile fail', err);
  26. swan.showToast({
  27. title: '上传失败',
  28. icon: none
  29. });
  30. },
  31. complete: () => {
  32. console.log('complete');
  33. }
  34. });
  35. this.uploadTask = uploadTask;
  36. }
  37. })
  38. },
  39. abortUploadFile() {
  40. this.uploadTask.abort();
  41. swan.showModal({
  42. title: 'title',
  43. content: "已断掉"
  44. });
  45. }
  46. });