使用wx.downloadFile下载文件得到的tempFile的后缀是bin,为什么?
发布于 5 年前 作者 tanxiulan 8279 次浏览 来自 问答

wx.downloadFile({

        url: e.currentTarget.dataset.localfilename,      //要预览的文件的地址

        header: {

          'Content-Type': 'application/xlsx',

        },

        success: function (res) {                           

          console.log(res, 'res'); // 这个返回的地址后缀就是bin

          if (res.statusCode === 200{       

            var Path = res.tempFilePath                     //返回的文件临时地址,用于后面打开本地预览所用

            wx.openDocument({

              filePath: Path,                               //要打开的文件路径

              success: function (res) {

                console.log('打开PDF成功');

              }

            })

          }

        },

        fail: function (res) {

          console.log(res);                                  //失败

        }

      })

返回结果如下

1 回复

content-type 设置为::“application/vnd.openxmlformats-officedocument.spreadsheetml.sheet” 或者“application/vnd.ms-excel” 试试

回到顶部