UploadTask.abort

解释:中断上传任务

# 方法参数

# 示例

在开发者工具中预览效果

百度智能小程序
请使用百度APP扫码

# 图片示例

# 代码示例

    <view class="wrap">
        <view class="card-area">
            <button bind:tap="uploadFile" type="primary" loading="{{loading}}" hover-stop-propagation="true">点击向服务器上传图片</button>
            <button bind:tap="abortUploadTask" type="primary" loading="{{loading}}" hover-stop-propagation="true" disabled="{{disabled}}">点击断掉前后端链接</button>
        </view>
    </view>
    
    
    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
                            });
                        }
                    });
                    this.uploadTask = uploadTask;
                }
            })
        },
        abortUploadFile() {
            this.uploadTask.abort();
            swan.showModal({
                title: 'title',
                content: "已断掉"
            });
        }
    });