UploadTask.offHeadersReceived

2020-08-20 17:54 更新
基礎(chǔ)庫(kù) 3.180.1 版本開(kāi)始支持。

解釋:取消監(jiān)聽(tīng)上傳的 HTTP Response Header 事件

方法參數(shù)

Function callback

代碼示例

<view>
    <button type="primary" bindtap="offHeadersReceived">取消 HTTP Response Header 的監(jiān)聽(tīng)</button>
</view>
Page({
    offHeadersReceived() {      
        swan.chooseImage({
            success: res => {
                let uploadTask = swan.uploadFile({
                    //開(kāi)發(fā)者服務(wù)器 url
                    url: 'https://smartprogram.baidu.com/xxx',

                    // 要上傳文件資源的路徑
                    filePath: res.tempFilePaths[0],

                    name: 'myfile',
                    header: {
                        'content-type': 'application/json'
                    },
                    formData: {
                        'user': 'swan'
                    },
                    success: () =>{
                        console.log('uploadFile success');
                    },
                    fail: err => {
                        console.log('uploadFile fail');
                    }
                });

                let cb = res => {
                    swan.showModal({
                        title: 'onHeadersReceived',
                        content: JSON.stringify(res)
                    });

                    // 不傳遞 cb 將刪除此對(duì)象上所有 HTTP Response Header 事件的回調(diào)函數(shù)
                    uploadTask.offHeadersReceived();
                };
                uploadTask.onHeadersReceived(cb);
            }
        })
    }  
});


以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)