uniapp App 下载二进制流xlsx

接口通过网页浏览器访问是能够正常下载一个xlsx类型的文件。但是通过调用uni.downloadFile方法下载该文件时候,临时文件没有带上后缀,而且文件名称还是接口名称。 

uni.downloadFile({
					url: 'https://www.example.com/file/test', //仅为示例,并非真实的资源
					responseType: 'blob',
					success: (res) => {
						if (res.statusCode === 200) {
							console.log('下载成功');
                            //更改文件名称
							// 拿到临时文件的绝对路径
							let filepathss = plus.io.convertLocalFileSystemURL(res.tempFilePath);
							// 通过这个路径来拿到他
							plus.io.resolveLocalFileSystemURL(filepathss, function(entry) {
								const tempFileName = entry.name;
								entry.getParent(function(parentDicEntry) {
									console.log(parentDicEntry.fullPath)
									entry.moveTo({
										fullPath: parentDicEntry.fullPath + '/'
									}, '新的文件名字.xlsx', function(newFile) {
										uni.openDocument({
											fileType: 'xlsx',
											filePath: newFile.fullPath,
											success: function(res2) {
												console.log('打开文档成功');
											},
											fail: function(err) {
												if (err.errCode == 1 || err
													.code == 1) {
													uni.showToast({
														title: `未找到能打开xlsx类型文件的手机应用`,
														icon: 'none'
													})
												}
												console.log(err)
											}
										});
									}, function(moveError) {
										uni.showToast({
											title: `已在第三方应用中打开过,请在第三方应用查看时保存`,
											icon: 'none'
										})
									})
								})
							})
						}
					}
				});
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值