收藏
回答

openDocument打开错误

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.openDocument 客户端 7.0.03 2.6.5




你好,我们有国外的同事在使用小程序的时候,用安卓下载并打开 pdf 文件会提示这个错误,错误如图,代码如下所示,请问是什么原因,国内安卓和海外 ios 没问题

打了 log,下载完显示指定目录文件是有大小的,但是去文件管理器里却找不到,国内安卓可以使用,并且能在文件管理器里找到


var that = this
    var ticketLocalPath = wx.env.USER_DATA_PATH + '/1.pdf'
    console.log(ticketLocalPath)
    wx.showLoading({
      title: '票券下载中',
    })
    wx.downloadFile({
      url: 'https://www.2paynow.cn/zhifu/merchant_material/eTicket2/472200101/tickets/ticket_190404105200_184030085.pdf',
      success: function(res) {
        console.log(res)
        var tempPath = res.tempFilePath //返回的文件临时地址,用于后面打开本地预览所用
        wx.getFileSystemManager().getFileInfo({
          filePath: tempPath,
          success: function(res) {
            console.log(res)
          },
        })
        wx.getFileSystemManager().saveFile({
          tempFilePath: tempPath,
          filePath: ticketLocalPath,
          success: function(res) {
            console.log('下载成功')
            wx.openDocument({
              filePath: ticketLocalPath,
              fileType: 'pdf',
              fail: function(res) {
                console.log(res)
                util.showToast("打开失败")
              },
              complete: function({
                result
              }) {
                wx.getFileSystemManager().getFileInfo({
                  filePath: ticketLocalPath,
                  success: function(res) {
                    console.log(res)
                  },
                })
                wx.hideLoading()
              }
            })
          },
          fail: function(res) {
            console.log(res)
            util.showToast("下载失败")
            wx.hideLoading()
          }
        })
      },
      fail: function(res) {
        console.log(res)
        util.showToast("下载失败")
        wx.hideLoading()
      }
    })


回答关注问题邀请回答
收藏

3 个回答

  • 黄思程
    黄思程
    2019-04-09

    直接用下载好的 tempFilePath,用 openDocument 打开可以吗

    2019-04-09
    有用
    回复 1
    • 王培烽
      王培烽
      2019-04-09

      也是不行的,去掉 save 也不行,但是很奇怪,文件大小都打出来了,调用openDocument却打不开

      2019-04-09
      回复
  • 灵芝
    灵芝
    2019-04-08

    你好,看看是否重复调用了该接口?

    麻烦提供出现问题的具体机型、微信版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    2019-04-08
    有用
    回复 2
    • 王培烽
      王培烽
      2019-04-08

      你好,只用一次函数,没有重复调用问题,

      代码片段是https://developers.weixin.qq.com/s/lIPmytma7Y7v

      国外的安卓都不行,包括

      锤子Pro2s

      三星S8+

      一加6T

      微信版本号是7.0.3

      2019-04-08
      回复
    • 张凡
      张凡
      2021-09-10
      你好,找到解决方法了吗?
      2021-09-10
      回复
  • 疯狂的小辣椒
    疯狂的小辣椒
    2019-04-08

    你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    2019-04-08
    有用
    回复
登录 后发表内容