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();
		}
	}
});
相关推荐
1234Wu10 分钟前
React Native 接入 eCharts
javascript·react native·react.js
abigale032 小时前
webpack+vite前端构建工具 -11实战中的配置技巧
前端·webpack·node.js
专注API从业者2 小时前
构建淘宝评论监控系统:API 接口开发与实时数据采集教程
大数据·前端·数据库·oracle
Joker`s smile2 小时前
Chrome安装老版本、不同版本,自制便携版本用于前端调试
前端·chrome
weixin_416639972 小时前
爬虫工程师Chrome开发者工具简单介绍
前端·chrome·爬虫
我是如子啊2 小时前
【解决“此扩展可能损坏”】Edge浏览器(chrome系列通杀))扩展损坏?一招保留数据快速修复
前端·chrome·edge
灵性花火2 小时前
Qt的前端和后端过于耦合(0/7)
开发语言·前端·qt
孤水寒月6 小时前
基于HTML的悬窗可拖动记事本
前端·css·html
祝余呀6 小时前
html初学者第一天
前端·html
脑袋大大的7 小时前
JavaScript 性能优化实战:减少 DOM 操作引发的重排与重绘
开发语言·javascript·性能优化