收藏
回答

wx.openDocument 在window PC端接口调用成功,打开文件失败,怎么解决?

以下是我的代码,我在手机端微信小程序调用都能打开显示,在mac的电脑上打开微信小程序也能下载打开,但是在window系统上的微信小程序上无法打开文件显示打开文件失败

downLoadMount(data) {
            let _this = this;
            let downUrl = (this.$config.baseUrl + 'api/member/downloadPdf?id=' + data.id);
            uni.showLoading({ title: '加载中' })
            uni.downloadFile({
                url: downUrl,
                success: function (res) {
                    let startPos = res.tempFilePath.lastIndexOf("/");
                    let fileName = res.tempFilePath.slice(startPos);
                    let filetype = 'pdf';


                    wx.getFileSystemManager().saveFile({
                        tempFilePath: res.tempFilePath,
                        filePath: `${wx.env.USER_DATA_PATH}/${fileName}`,
                        success: (res) => {
                            console.log('File saved successfully:', res);
                            wx.openDocument({
                                filePath: res.savedFilePath,
                                showMenu: true,
                                fileType: filetype,
                                success: (res) => {
                                    console.log('Document opened successfully',res);
                                    _this.$util.showToast({ title: '下载成功' });
                                },
                                fail:(err)=>{
                                    console.error('Failed to open document:', err);
                                },
                            });
                        },
                        fail: (err) => {
                            _this.$util.showToast({
                                title: '下载失败'
                            });
                            console.error('Failed to save file:', err);
                        },
                        complete: () => {
                            uni.hideLoading();
                        }
                    });
                },
                fail(err) {
                    _this.$util.showToast('下载失败');
                    uni.hideLoading();
                }
            })
        },

以下是我在微信开发者工具中调试window pc端小程序的打印:

显示调用下载文件和wx.openDocument成功,但是最终打开文件的弹出框显示打开文件失败

其他端都是正常的,怎么解决在window pc端微信小程序打开文件失败?

回答关注问题邀请回答
收藏

1 个回答

  • 社区技术运营专员--阳光
    社区技术运营专员--阳光
    09-25

    验证可以正常打开,给个代码片段看看呢(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    09-25
    有用
    回复
登录 后发表内容