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();
		}
	}
});
相关推荐
Eider19984 分钟前
Python基础知识之并发相关-2
开发语言·前端·python
用户69371750013846 分钟前
AI 能写代码,但工程架构还是应该由人来定
前端·后端
Hilaku14 分钟前
前端的技术判断力是怎么练出来的?
前端·javascript·程序员
悠仁さん16 分钟前
【C++】set map 使用
java·前端·c++
用户0936717554119 分钟前
用 4500 行 TypeScript 复刻了童年方格纸上的海战棋
前端·vue.js
CCIE-Yasuo22 分钟前
网络安全-学习web开发-基础概念、常用标签
前端·学习
凉介川28 分钟前
给 DeepSeek Harness 写插件:按扩展名接管 Windows 右键打开
前端
涛涛ing28 分钟前
Pretext之后,2026年的前端正在被“平台”和“AI”同时重写
前端
Csvn1 小时前
Worker 与 OffscreenCanvas
前端
Csvn1 小时前
图片字体
前端