使用wx.downloadFile下载文件 后缀名为unknown
发布于 5 年前 作者 weihou 877 次浏览 来自 问答

文件下载 下载下来的文件后缀名为unknown 使用opendocument提示格式不支持

代码:

downLoadFile:function(){

   var that = this;

   var url = ‘https://*******/highTechNotice?fileId=’ + that.data.company.fileId + ‘&name=.doc’;// + that.data.company.fileName

   console.log(url);

   const downloadTask =  wx.downloadFile({

       url: url,

       success: function (res) {

       debugger;

       console.log(res);

       // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容

       if (res.statusCode === 200) {

       var filePath = res.tempFilePath

       wx.saveFile({

           tempFilePath: filePath,

           success: function (res) {

           console.log(res);

           var savedFilePath = res.savedFilePath

           },

           fail: function (err) {

           console.log(err);

           }

       })

       wx.openDocument({

           filePath: filePath,

           success: function (res) {

           console.log(‘打开文档成功’)

           },

           fail: function (err) {

           console.log(err);

           },//请求失败

       })

      }

   },

   fail: function (err) {

   console.log(err)

   }

})

回到顶部