UploadTask

解释:上传任务对象

# 方法参数

# 示例

在开发者工具中预览效果

# 扫码体验

请使用百度APP扫码

# 图片示例

# 代码示例

    <button bindtap="createUploadTask">创建uploadFile实例对象</button>
    
    
    Page({
        data: { },
        createUploadTask() {
            const uploadTask = swan.uploadFile({
                url: 'https://smartprogram.baidu.com/mappconsole/api/checkFile', 
                filePath: "https://127.0.0.1:8199/program/29acd176e8e8fc95c065…e8fc95c065789eddb01303-0/tmp/1572939723264529.png",
                name: 'myfile',
                header: {
                    'content-type': 'application/json'
                },
                formData: {
                    'user': 'swan'
                },
                success: res => {
                    swan.showToast({
                        title: '上传成功',
                        icon: 'none'
                    });
                    console.log('uploadFile success', res);
                    this.setData({filePath});
                },
                fail: err => {
                    swan.showToast({
                        title: '上传失败',
                        icon: none
                    });
                    console.log('uploadFile fail', err);
                },
                complete: () => {
                    console.log('complete');
                }
            });
            console.log('res', uploadTask);
            swan.showModal({
                title: '创建' + uploadTask._reqId,
                content: JSON.stringify(uploadTask)
            });
        }
    });