下载后预览pdf 报错
发布于 6 年前 作者 qjiang 1922 次浏览 来自 问答
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);
                    },
                })
            },
回到顶部