​wx.openDocument() 打不开pdf文档,文件下载好了没反应?
发布于 4 年前 作者 liuwei 1351 次浏览 来自 官方Issues

wx.downloadFile({

url: https://www.xxxx.com/api/wechat/nfiles/download?fileid=1&userid=1, //仅为示例,并非真实的资源

success: function (res) {

        // this.setData({

        //   files: res.tempFilePath

        // })

        wx.openDocument({

            filePath: res.tempFilePath,

            success: function (res) {

            console.log(‘打开文档成功’)

    }

})

}

文件下载好了没反应,提示unable to find app to open this type of document

2 回复

解决了,必须要加fileType: “pdf” 才可打开

wx.downloadFile({

// 示例 url,并非真实存在

url: https://www.xxxx.com/api/wechat/nfiles/download?fileid=1&userid=1,

success: function (res) {

const filePath = res.tempFilePath

//更具filePath确定文档类型

console.log(‘打开’ +filePath)

wx.openDocument({

filePath: filePath,

fileType: “pdf”,

success: function (res) {

console.log(‘打开文档成功’)

}

})

}

})

留眼,混点经验…

回到顶部