wx.downloadFile下载图片,出现很奇怪的错误
发布于 5 年前 作者 fsu 5224 次浏览 来自 问答

//index.js
//获取应用实例
var app = getApp()
var that;
Page({
  data: {
  },
  onLoad: function () {
    that = this
    setdata(that)
  }
})
function setdata(that){
  //下载到本地
  wx.downloadFile({
    url: “https://wx.qlogo.cn/mmopen/vi_32/ToicT5W4iaz6W7V7GxjNoa9ibXiaN9FGI49bSTTtYF6rVpaGLAQMa3wPsbdK3ns29ZA44ib8rFoUHssZapd7eCn03fA/0”,
    success: function (res) {
      console.log(“image”, res)
      var tempFilePaths = res.tempFilePath
      that.setData({
        image: tempFilePaths//显示的图片
      })
    },
    fail: function (res) {
      wx.showModal({
        title: ‘提示2’,
        content: JSON.stringify(res)+’’,
      })
    }
  })
}

如果我点击了“打开调试”就可以下载图片并且显示在页面上,如果我点击“关闭调试”就会进入fail: function (res)方法里面。

图1:没有点击打开调试

图2:点击了打开调试

1 回复

出现这样的原因是,在调试状态,不会审核我的地址是否是是在微信公众后台配置过得。这个地址我是直接用我的微信头像调用的。

我在微信公众后台配置的是地址的https而调用下载图片时用http也可以下载,但是有时候会下载失败。

回到顶部