电脑用downloadFile没问题,真机测试就有问题了,下载不了
发布于 6 年前 作者 guiyinggao 10946 次浏览 来自 问答

那些域名什么之类的都已经配好了,图片上传查看是没问题的,文件下载就真机有问题

 ViewFile:function(e){

    let url = e.currentTarget.dataset.url;

    console.log(url);

    let that=this;

    if (url == undefined || url == null{

      util.showError("参数有误,请和管理员联系!");

      return;

    }

    wx.downloadFile({

      url: url,

      success(res){

        console.log(res);

        if(res.statusCode==200){

          const tempFilePath=res.tempFilePath

          wx.openDocument({

            filePath: tempFilePath,

            success: function (res) {

            

            },

            fail:function(res){

              util.showError('打开失败,文件不存在')

            }

          })

        }

      },

     fail:function(res){

       console.log(res);

       util.showError('文件下载失败,请和管理员联系');

     }

    })

  }

4 回复

你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

😍 😍 😍 😍 😍 😍 😍 😍 🌹 🌹 🌹 🌹 🌹 🌹 🌹 🌹

报错提示说的很清楚哇,文件的链接必须是http://或者https://开头的

而你前面不知道怎么操作的,已经把文件下载到本地了,所以你输出的文件的地址是wxfile://

好好检查下你自己代码咯

ViewFile:function(e){
    let url = e.currentTarget.dataset.url;
    console.log(url);
    let that=this;
    if (url == undefined || url == null) {
      util.showError("参数有误,请和管理员联系!");
      return;
    }
    wx.downloadFile({
      url: url,
      success(res){
        console.log(res);
        if(res.statusCode==200){
          const tempFilePath=res.tempFilePath
          wx.openDocument({
            filePath: tempFilePath,
            successfunction (res{
            
            },
            fail:function(res){
              util.showError('打开失败,文件不存在')
            }
          })
        }
      },
     fail:function(res){
       console.log(res);
       util.showError('文件下载失败,请和管理员联系');
     }
    })
  }
debug时候到wx.downloadFile的url哪里就直接跳到fail了
回到顶部