赞
踩
之前发过微信小程序预览文件自定义名称
具体是怎么使用,建议去我另一篇文章看一下
今天这篇文章的目的是什么嘞
原因是因为再安卓手机会出现预览文件的临时路径名称
再ios手机就没有这个问题
现在需要自己去定义文件名称
下面方法就是去预览文件但是,会有一个临时文件路径的名称
- wx.downloadFile({
- url: '路径', // 自己换个其他的地址("https://www.xxxxx.com/file/用户协议.pdf")
- filePath: filePath,
- success: function(res) {
- console.log('downloadFile', res);
- if (res.statusCode != 200) {
- return false
- }
- console.log(res.tempFilePath);
- var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
-
- wx.openDocument({
- filePath: Path,
- fileType: 'docx',
- showMenu: true,
- success: function(res) {
- console.log(res);
- console.log(9999);
- }
- })
- },
- fail: function(err) {
- console.log(err);
- }
- })

正确的出现预览的文件名称应该是
-
- let filePath = `${wx.env.USER_DATA_PATH}/自定义名称.docx`
- wx.downloadFile({
- url: '路径', // 自己换个其他的地址("https://www.xxxxx.com/file/用户协议.pdf")
- filePath: filePath,
- success: function(res) {
- console.log('downloadFile', res);
- if (res.statusCode != 200) {
- return false
- }
-
-
- var Path = res.filePath //返回的文件临时地址,用于后面打开本地预览所用
- wx.openDocument({
- filePath: Path,
- fileType: 'docx',
- showMenu: true,
- success: function(res) {
- console.log(res);
- console.log(9999);
- }
- })
- },
- fail: function(err) {
- console.log(err);
- }
- })

res.tempFilePath); 临时文件路径,名称
res.filePath 自定义文件路径,名称
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。