下载图片到本地,IDE和开启调试模式都可以,但是关闭调试真机就不能下载
发布于 6 年前 作者 chao63 4329 次浏览 来自 问答

下载图片到本地,IDE和开启调试模式都可以,但是关闭调试真机就不能下载。代码如下:

 wx.authorize({

      scope: ‘scope.writePhotosAlbum’,

      success() {

        obj._downloadFile(imgUrl);

      },fail:function(){

        wx.hideToast();

        wx.showToast({

          title: ‘授权失败’,

          image: ‘/images/close-white.png’,

          duration: 2000

        })

      }

    })

,

_downloadFile(imgUrl){

    console.log(imgUrl)

    wx.downloadFile({

      url: imgUrl,

      success: function (res) {

        wx.saveImageToPhotosAlbum({

          filePath: res.tempFilePath,

          success: function () {

            wx.hideToast();

            wx.showToast({

              title: ‘图片下载成功’,

              icon: ‘success’,

              duration: 2000

            })

          },

          fail: function () {

            wx.hideToast();

          }

        })

        // wx.saveFile({

        //   tempFilePath: res.tempFilePath,

        //   success: function (res) {

        //     wx.hideToast();

        //     wx.showToast({

        //       title: ‘图片下载成功’,

        //       icon: ‘success’,

        //       duration: 2000

        //     })

        //   }

        // });

      }

    });

  }

2 回复

"IDE和开启调试模式都可以,但是关闭调试真机就不能"一般是域名不合法,需要去自己的微信公众平台(https://mp.weixin.qq.com)->设置->开发设置->服务器域名里配置一下

多谢大哥,我试试

回到顶部