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();
		}
	}
});
相关推荐
白泽_hunter2 分钟前
搞懂 JS 数据类型:从 typeof 到手写完整类型判断,一张图理清
前端
日光倾35 分钟前
TypeScript 随手记 —— 1
前端·javascript·typescript
自学it的攻城狮1 小时前
elpis-core ,koa实现的系统底座, 沉淀80% 的通用能力,剩下20% 用于定制化开发
前端
CappuccinoRose2 小时前
模块化体系
前端·import·export·es modules
AIDANHANG2 小时前
放开靠时间戳对日志前先核请求ID跨服务传播与采样关联
前端·人工智能
Buke..3 小时前
【APP 逆向】哔哩哔哩 sign 参数逆向(下):OLLVM 混淆还原 sign 算法
java·javascript·爬虫·python·算法
半生过往4 小时前
前端学 Java 课程笔记
java·前端·笔记
广州华水科技4 小时前
2026年单北斗GNSS变形监测系统推荐,破解水库安全监测难题
前端
独爱香菜5 小时前
Next.js 15 + Cloudflare Workers 实战:零中间件多语言 SEO 站点架构
前端
计算机魔术师5 小时前
DeepSeek、Qwen3比肩GPT-5,本地跑大模型的时代来了
前端