PC端小程序使用wx.openDocument打开文件报错文件损坏问题?
发布于 4 年前 作者 yan39 5769 次浏览 来自 官方Issues

在开发模式中可以打开,但是在线上版本中以微信文档预览窗口打开显示文件损坏

3 回复

PC端这个接口我印象中一直就有问题,官方以前也说过,包括pdf很多人都反馈打不开,提示文件错误。

请问你打开的文件格式是什么?PC端打开xlsx格式也遇到这个问题了,手机端正常的

是不是官方不支持的原因https://developers.weixin.qq.com/community/develop/doc/0006a6b6f2cf60404299d51ab56809

代码熟悉了解清楚后,再自己改

https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.openDocument.html

tempFilePath

wx.downloadFile({
  // 示例 url,并非真实存在
  url: 'http://example.com/somefile.pdf',
  success: function (res) {
    const filePath = res.tempFilePath
    wx.openDocument({
      filePath: filePath,
      success: function (res) {
        console.log('打开文档成功')
      }
    })
  }
})

https://developers.weixin.qq.com/miniprogram/dev/api/file/wx.saveFile.html

保存文件到本地。注意:saveFile 会把临时文件移动,因此调用成功后传入的 tempFilePath 将不可用

回到顶部