收藏
回答

下载后预览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);
                    },
                })
            },


最后一次编辑于  2019-05-05
回答关注问题邀请回答
收藏

1 个回答

  • 是小白啊
    是小白啊
    2019-05-05

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

    2019-05-05
    有用
    回复 4
    • 闫明
      闫明
      2019-05-05

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

      2019-05-05
      回复
    • 是小白啊
      是小白啊
      2019-05-05回复闫明

      这这样试下?

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

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

      2019-05-05
      回复
    • hexford~🐶
      hexford~🐶
      2019-06-17

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

      2019-06-17
      回复
登录 后发表内容