收藏
回答

wx.openDocument在ios上好使,但是在安卓上不可以?

openDocument:fail:file type not supported"一直提示这个!文件是docx文件

华为荣耀10和一加 8T都不好使



let file = wx.getFileSystemManager()
let path = wx.env.USER_DATA_PATH + '/'+res.filename
let fileType = res.filename.split('.')
let openPath = escape(path)
console.log('fileType',fileType)
//小程序暂不支持打开压缩文件
if(fileType.indexOf('zip') != -1){
  uni.showToast({
    icon: 'none',
    title: '对不起,无法打开压缩文件!',
    duration: 2000
  })
}
//小程序打开text文件时,修改文件后缀doc打开
if(fileType=='text'){
  path = wx.env.USER_DATA_PATH + '/'+fileType[0]+'.doc'
}
file.writeFile({
  filePath: path,
  data: res.attachment,
  encoding: 'base64',
  success: res => {
    console.info('file upload success',res)
        console.log('openPath',openPath)
        if(this.fileTypeList.concat(fileType)){
          console.log('open file',path)
          console.log('open fileType',fileType[1])
          uni.openDocument({
            filePath: path,
            fileType: fileType[1],
            // 如果文件名包含中文,建议使用escape(res.tempFilePath)转码,防止ios和安卓客户端导致的差异
            success: function(res) {
              console.log('打开文档成功');
            },
            fail: res => {
              console.info('open file error',res)
            }
          });
        }else{
          uni.previewImage({
            urls: [path]
          })
        }

  },
  fail: res => {
    console.info('file upload error',res)
  }
})


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

1 个回答

登录 后发表内容
问题标签