收藏
回答

ios中 worker 上传文件无法监听上传进度?

// workers/request/upload.js
const util = require("./util")
const config = require("./config")
const createSign = function (time{
    var key = config.key;
    return util.base64.encode(util.md5(time + key + time))
};
const upload = function (data{
    var time = parseInt(Date.now() / 1000);
    var url = data.data;
    let uploadTask = worker.uploadFile({
        filePath: url.url,
        name: 'file',
        header: {
            "timestamp": time,
            "sign": createSign(time.toString()),
        },
        url: config.api_url + 'common/upload',
        success(res) {
            var result = JSON.parse(res.data);
            worker.postMessage({
                type'upload',
                index: data.index,
                ...result
            })
            worker.postMessage({
                type'progress',
                index: data.index,
                progress: 100
            })
        },
        timeout: 0,
        fail(err) {
            worker.postMessage({
                type'upload',
                code: 1,
                index: data.index,
                msg: '上传失败'
            })
        }
    })


    uploadTask.onProgressUpdate(function (res{
        console.log(res) // ios无法打印
        worker.postMessage({
            type'progress',
            index: data.index,
            progress: res.progress
        })
        if (res.progress == 100) {
            uploadTask.offProgressUpdate()
        }
    })
}


worker.onMessage(data => {
    upload(data)
})
回答关注问题邀请回答
收藏

1 个回答

  • 马良
    马良
    2021-06-18

    急,感谢

    2021-06-18
    有用
    回复 1
    • After_Rain
      After_Rain
      2022-06-09
      您好,  问题解决了吗  我也遇到了这个问题
      2022-06-09
      回复
登录 后发表内容