UploadTask.abort
解释:中断上传任务
方法参数
无
示例
扫码体验
请使用百度APP扫码
图片示例
代码示例
Page({
data: { },
uploadFile() {
swan.chooseImage({
success: res => {
const uploadTask = swan.uploadFile({
url: 'https://smartprogram.baidu.com/mappconsole/api/checkFile',
filePath: res.tempFilePaths[0],
name: 'myfile',
header: {
'content-type': 'application/json'
},
formData: {
'user': 'swan'
},
success: res => {
swan.showModal({
title: 'title',
content: "上传成功"
});
console.log('uploadFile success', res);
this.setData({filePath});
},
fail: err => {
console.log('uploadFile fail', err);
swan.showToast({
title: '上传失败',
icon: none
});
},
complete: () => {
console.log('complete');
}
});
this.uploadTask = uploadTask;
}
})
},
abortUploadFile() {
this.uploadTask.abort();
swan.showModal({
title: 'title',
content: "已断掉"
});
}
});