UploadTask.abort
2020-08-20 17:53 更新
解释:中断上传任务
方法参数
无
示例
图片示例
代码示例
<view class="wrap">
<view class="card-area">
<button bind:tap="uploadFile" type="primary" hover-stop-propagation="true">点击向服务器上传图片</button>
<button bind:tap="abortUploadFile" type="primary" hover-stop-propagation="true" disabled="{{disabled}}">点击断掉前后端链接</button>
</view>
</view>
Page({
uploadFile() {
this.setData({
disabled: false
});
swan.chooseImage({
success: res => {
const uploadTask = swan.uploadFile({
url: 'https://xxxx', // 仅为示例,并非真实的接口地址
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'
});
}
});
this.uploadTask = uploadTask;
}
});
},
abortUploadFile() {
this.uploadTask.abort();
swan.showModal({
title: 'title',
content: '已断掉'
});
}
});
以上内容是否对您有帮助:
更多建议: