// 下载关键测试代码如下
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;
}