微信二维码
微博二维码
qq号二维码

天津WEB前端培训-微信小程序之wx.uploadFile

夏磊银 2019.11.30 18794人浏览
微信小程序之wx.uploadFile

视频示范实例:https://ke.qq.com/course/1712225?taid=7953523519660129


wx.uploadFile(Object object)

将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求,其中 content-type 为 multipart/form-data

url:开发者服务器地址

filePath:要上传文件资源的路径

name:文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容

header:HTTP 请求 Header,Header 中不能设置 Referer

formData:HTTP 请求中其他额外的 form data

success:接口调用成功的回调函数

fail:接口调用失败的回调函数

complete:接口调用结束的回调函数(调用成功、失败都会执行)


实例

wx.chooseImage({

  success (res) {

    const tempFilePaths = res.tempFilePaths

    wx.uploadFile({

      url: 'https://example.weixin.qq.com/upload',

      filePath: tempFilePaths[0],

      name: 'file',

      formData: {

        'user': 'test'

      },

      success (res){

        const data = res.data

        //do something

      }

    })

  }

})


分享到:
天津UI设计培训-CleanPNG免抠素材网站
  • 2020.11.30
  • 天津室内设计培训新纪元:AI与Stable Diffusion技术的前沿培训解析
  • 2024.03.13