当前位置:   article > 正文

uniapp 微信小程序预览文件自定义名称_小程序uni.downloadfile名字自定义

小程序uni.downloadfile名字自定义

之前发过微信小程序预览文件自定义名称

具体是怎么使用,建议去我另一篇文章看一下

今天这篇文章的目的是什么嘞

原因是因为再安卓手机会出现预览文件的临时路径名称

再ios手机就没有这个问题

现在需要自己去定义文件名称

下面方法就是去预览文件但是,会有一个临时文件路径的名称

  1. wx.downloadFile({
  2. url: '路径', // 自己换个其他的地址("https://www.xxxxx.com/file/用户协议.pdf")
  3. filePath: filePath,
  4. success: function(res) {
  5. console.log('downloadFile', res);
  6. if (res.statusCode != 200) {
  7. return false
  8. }
  9. console.log(res.tempFilePath);
  10. var Path = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
  11. wx.openDocument({
  12. filePath: Path,
  13. fileType: 'docx',
  14. showMenu: true,
  15. success: function(res) {
  16. console.log(res);
  17. console.log(9999);
  18. }
  19. })
  20. },
  21. fail: function(err) {
  22. console.log(err);
  23. }
  24. })

正确的出现预览的文件名称应该是

  1. let filePath = `${wx.env.USER_DATA_PATH}/自定义名称.docx`
  2. wx.downloadFile({
  3. url: '路径', // 自己换个其他的地址("https://www.xxxxx.com/file/用户协议.pdf")
  4. filePath: filePath,
  5. success: function(res) {
  6. console.log('downloadFile', res);
  7. if (res.statusCode != 200) {
  8. return false
  9. }
  10. var Path = res.filePath //返回的文件临时地址,用于后面打开本地预览所用
  11. wx.openDocument({
  12. filePath: Path,
  13. fileType: 'docx',
  14. showMenu: true,
  15. success: function(res) {
  16. console.log(res);
  17. console.log(9999);
  18. }
  19. })
  20. },
  21. fail: function(err) {
  22. console.log(err);
  23. }
  24. })

res.tempFilePath);   临时文件路径,名称
res.filePath   自定义文件路径,名称

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/264130
推荐阅读
相关标签
  

闽ICP备14008679号