uni-app下载文件在ios下失败

// 下载关键测试代码如下
downloadFileAction() {
    const downloadTask = uni.downloadFile({
        url: 'http://www.test.com/文件.zip', //仅为示例,并非真实的资源
        success: (res) => {
            if (res.statusCode === 200) {
                console.log('下载成功');
            }
            let that = this;
            
            uni.saveFile({
                tempFilePath: this.fileNameEscape(res.tempFilePath),
                    success: function(red) {
                        that.luj = red.savedFilePath
                        console.log(red)
                    }
                });
            }
        });

        downloadTask.onProgressUpdate((res) => {
            console.log('下载进度' + res.progress);
            console.log('已经下载的数据长度' + res.totalBytesWritten);
            console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
    });
},
/**
 * ios下文件名中文处理
 * @param {String} filename
 */
fileNameEscape(filename) {
    if (uni.getSystemInfoSync().platform == "ios") {
        filename = escape(filename);
    }
    return filename;
}

 

posted on 2022-01-12 10:48  天空中的云~飞起来了  阅读(847)  评论(0)    收藏  举报