uniapp 下载文件到手机

下载后端传递过来的文件

javascript 复制代码
let thil = this
uni.showLoading({
	title: '下载中',
	mask:true
})
uni.downloadFile({
	url: '接口地址', //仅为示例,并非真实的资源
	header: {
		"Authorization": 'token'
	},
	responseType: 'blob',
	success: (res) => {
		if (res.statusCode === 200) {
			uni.hideLoading();
			//更改文件名称
			// 拿到临时文件的绝对路径
			let filepathss = plus.io.convertLocalFileSystemURL(res.tempFilePath);
			// 通过这个路径来拿到他
			plus.io.resolveLocalFileSystemURL(filepathss, function(entry) {
				const tempFileName = entry.name;
				entry.getParent(function(parentDicEntry) {
					entry.moveTo({
						fullPath: parentDicEntry.fullPath + '/'
					}, `${thil.$u.guid(20)}.zip`, function(newFile) {
						uni.openDocument({
							fileType: 'zip',
							filePath: newFile.fullPath,
							success: function(res2) {

							},
							fail: function(err) {
								if (err.errCode == 1 || err
									.code == 1) {
									uni.showToast({
										title: `未找到能打开xlsx类型文件的手机应用`,
										icon: 'none'
									})
								}
							}
						});
					}, function(moveError) {
						uni.showToast({
							title: `已在第三方应用中打开过,请在第三方应用查看时保存`,
							icon: 'none'
						})
					})
				})
			})
		} else {
			uni.hideLoading();
		}
	}
});
相关推荐
小兵张健7 分钟前
价值1000的 AI 工作流:Codex 通用前端协作模式
前端·aigc·ai编程
sunny_16 分钟前
面试踩大坑!同一段 Node.js 代码,CJS 和 ESM 的执行顺序居然是反的?!99% 的人都答错了
前端·面试·node.js
拉不动的猪29 分钟前
移动端调试工具VConsole初始化时的加载阻塞问题
前端·javascript·微信小程序
ayqy贾杰2 小时前
Agent First Engineering
前端·vue.js·面试
IT_陈寒2 小时前
SpringBoot实战:5个让你的API性能翻倍的隐藏技巧
前端·人工智能·后端
iceiceiceice3 小时前
iOS PDF阅读器段评实现:如何从 PDFSelection 精准还原一个自然段
前端·人工智能·ios
大金乄3 小时前
封装一个vue2的elementUI 表格组件(包含表格编辑以及多级表头)
前端·javascript
葡萄城技术团队4 小时前
【性能优化篇】面对万行数据也不卡顿?揭秘协同服务器的“片段机制 (Fragments)”
前端
程序员阿峰4 小时前
2026前端必备:TensorFlow.js,浏览器里的AI引擎,不写Python也能玩转智能
前端
Jans4 小时前
Shipfe — Rust 写的前端静态部署工具:一条命令上线 + 零停机 + 可回滚 + 自动清理
前端