在微信调试中,wx.downloadFile有一定几率预览不了,为啥?
发布于 5 年前 作者 qiumin 6861 次浏览 来自 官方Issues

如下我下载预览附件的代码,为什么在微信中调试,点击10次,有1-2次会预览不了,控制台每次点击都是success的,为啥呢?

(使用PDF、XLS、DOC文件测试)

openDoc: function (e) {
    console.log(e)
    let filename = e.currentTarget.dataset.filename;
    let index = filename.lastIndexOf(".");
    let suffix = filename.substr(index + 1);
    console.log(suffix);
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    console.log(e)
    wx.downloadFile({
      url: app.globalData.rooturl +'accessory/download?id='+e.currentTarget.dataset.id,
      success: function (res) {
        var filePath = res.tempFilePath
        wx.openDocument({
          filePath: filePath,
          fileType: suffix,
          success: function (res) {
            console.log(filePath)
            console.log(res)
            console.log('打开文档成功')
            wx.hideLoading();
          },
          fail: function (res) {
            console.log(res);
            wx.hideLoading();
            wx.showModal({
              title: '信息',
              content: res.errMsg,
              showCancel: false,
              success(res) {
                if (res.confirm) {
                  console.log('F')
                }
              }
            })
          },
          complete: function (res) {
            console.log('完成操作')
          }
        })
      }
    })
  },
1 回复

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

回到顶部