test(){
console.log('测试下载文件');
let that = this;
const downloadTask = uni.downloadFile({
// url: 'https://yxdj-res.oss-cn-shenzhen.aliyuncs.com/redaudio.mp3', //下载地址
url: 'https://yxdj-res.oss-cn-shenzhen.aliyuncs.com/msdj2024.apk',
success: (res) => {
console.log('success:'+JSON.stringify(res));
if (res.statusCode === 200) {
console.log('下载成功');
}
},fail: (error) => {
console.log('error:'+JSON.stringify(error));
}
});
downloadTask.onProgressUpdate((res) => {
console.log('下载进度' + res.progress);
console.log('已经下载的数据长度' + res.totalBytesWritten);
console.log('预期需要下载的数据总长度' + res.totalBytesExpectedToWrite);
// 满足测试条件,取消下载任务。
if (res.progress > 50) {
// downloadTask.abort();
}
});
}
0 个回复