uni-app安卓端打开文件(PDF,img)

问题:使用uni-app开发过程中遇到一个需求,后台给出PDF预览的链接,在手机上查看pdf文件

解决办法:

showPdf: function(fileId) {
    uni.downloadFile({
        // 下面一行是拼接预览PDF的地址!!!
        url: this.$api.PDF_VIEW + fileId,
        success: function(res) {
            var filePath = res.tempFilePath;
            if (!filePath) return

            uni.openDocument({
                filePath: filePath,
                success: function(res) {
                    console.log('打开文档成功');
                }
            });
        }
    });
},

备注 api.js中配置预览地址

PDF_VIEW: BaseUrl +'/api/file-manage/pdf-view?fileId=', // 展示pdf
posted @ 2020-04-25 23:22  小方块的世界  阅读(4737)  评论(0)    收藏  举报