微信小程序-wx.uploadFile

来源:互联网 发布:淘宝怎么收藏店铺啊 编辑:程序博客网 时间:2024/04/28 01:36

微信小程序-文件上传

官方接口代码如下:

wx.chooseImage({  success: function(res) {    var tempFilePaths = res.tempFilePaths    wx.uploadFile({      url: 'http://example.weixin.qq.com/upload',       //仅为示例,非真实的接口地址      filePath: tempFilePaths[0],      name: 'file',      formData:{        'user': 'test'      },      success: function(res){        var data = res.data        //do something      }    })  }})

这里要说明一下:

  1. 上传服务器地址须为https,官方实例有误。
  2. 客户端得是 HTTPS POST 请求。
  3. PC端也可上传文件,腾讯已经优化。
  4. 小程序后台需要配置相应地址。
0 0