微信小程序把玩(三十一)wx.uploadFile(object), wx.downloadFile(object) API

反正我是没有测通这两个API!!!!不知道用的方式不对还是其他的!!!先记录下回头再说。。。

主要方法:

wx.uploadFile(OBJECT)上传

微信小程序把玩(三十一)wx.uploadFile(object), wx.downloadFile(object) API

wx.downloadFile(OBJECT)下载

微信小程序把玩(三十一)wx.uploadFile(object), wx.downloadFile(object) API

wxml

<button type="primary" bindtap="listenerButtonDownLoadFile">下载图片</button>

<image src="{{resource}}" style="width:100%; height: 80%"/>

js

Page({
  data:{
    // text:"这是一个页面"
    resource: ''
  },
  onLoad:function(options){
    // 页面初始化 options为页面跳转所带来的参数
  },
  /**
   * 下载文件
   */
  listenerButtonDownLoadFile: function() {
      var that = this;
      wx.downloadFile({
          url: 'https://t2.27270.com/uploads/tu/201609/240/1mb2dybkw2x.jpg',
          type: 'image',
          success:function(res){
              console.log(res.tempFilePath);
              that.setData({
                  resource: res.tempFilePath,
              })
          },
          fail:function(err){
              console.log(err)
          },
          complete:function(e) {
              console.log(e)
          }
      })
  }
})