downloadFile(url, name) {
uni
.downloadFile({
url,
success: res => {
if (res.statusCode === 200) {
this.downloading = false;
}
const fileSaveUrl = plus.io.convertLocalFileSystemURL(res.tempFilePath);
plus.io.resolveLocalFileSystemURL(fileSaveUrl, entry => {
entry.getParent(_oldFile => {
entry.moveTo(_oldFile, '/' + name, newFilePath => {
this.saveFile(newFilePath.fullPath);
});
});
});
}
})
.onProgressUpdate(res => {
if (res.progress > 0) {
this.downloading = true;
}
this.progress = res.progress;
});
},
saveFile(tempFilePath) {
uni.saveFile({
tempFilePath,
success: res => {
this.downloading = false;
uni.showModal({
title: '提示',
content: `文件已保存:${tempFilePath}`,
cancelText: '我知道了',
confirmText: '打开文件',
success: ({ confirm }) => {
if (confirm) {
uni.openDocument({
filePath: tempFilePath,
success: () => {
console.log('成功打开');
}
});
}
}
});
}
});
}
uniapp下载并改文件名-可通信h5
最新推荐文章于 2024-02-28 15:00:24 发布