收藏
回答

下载后预览pdf 报错

down_file: function() {
                var _this = this;
                const downloadTask = wx.downloadFile({
                    url: 'https://www.2paynow.cn/zhifu/merchant_material/eTicket2/472200101/tickets/ticket_190404105200_184030085.pdf',
                    filePath: `${wx.env.USER_DATA_PATH}/` + 'hello.pdf',
                    success: function(res) {
                        // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
                        console.log(34, res)
                        if (res.statusCode === 200) {
                             
                                wx.openDocument({
                                    filePath: `${wx.env.USER_DATA_PATH}/` + 'hello.pdf',
                                    // filePath: res.tempFilePath,
                                    fileType: 'pdf',
                                    success(res) {
                                        console.log('打开文档成功')
                                    },
                                    fail(e) {
                                        // console.log(70, e);
                                    }
                                })
 
                        }
                    },
 
                    fail(e) {
                        console.log(77, e);
                    },
                })
            },


最后一次编辑于  05-05  (未经腾讯允许,不得转载)
邀请回答
复制链接收藏投诉关注问题回答

1 个回答

  • 是柿子啊
    是柿子啊
    05-05

    麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)

    05-05
    赞同
    回复 4
    • 闫明
      闫明
      05-05

      https://developers.weixin.qq.com/s/WolkQ8mK7X8l

      05-05
      回复
    • 是柿子啊
      是柿子啊
      05-05回复闫明

      这这样试下?

      05-05
      回复
    • 闫明
      闫明
      05-05

      我试过,这样预览文件后右上角发送给自己,还要改名字。我之前那样不需要改名字,用着没问题,就是有个报错,很烦

      05-05
      回复
    • sanford🐶~
      sanford🐶~
      06-17

      传入了 filePath 后就没有 tempFilePath了,去掉 filePath 或者 openDocument 接口里用 res.filePath 就可以了

      06-17
      回复