xhrr

文档中上传文件  wx.uploadFile只能上传一个文件同时携带其他参数,但是如果需要向接口传两个及以上文件形式参数时需要借助 Multipart 实现

1. utils下创建Multipart.min.js文件

  https://github.com/supperchong/wx-multipart  中下载

2. 在需要的页面引入

  const Multipart = require(\'../../utils/Multipart.min.js\') 

 async setWater(){
    let
fields =[{
      name:\'username\',
      value:\'小黄\'
    },{
      name:\'number\',
      value:\'13812345678\'
    }]

      let files=[
        {
          filePath: this.data.step1ImgFile,  //value
          name: \'img\'       //key
        },
        {
          filePath: this.data.step2ImgFile,
          name: \'wm\'
        }
      ]
      let res = await new Multipart({
        fields, //非文件参数
        files    //文件参数
      }).submit(\'http://xxx.xx.xx.xx:xxx/api/xxx\')
      console.log(res)
}

 

分类:

技术点:

相关文章:

  • 2021-12-13
  • 2021-09-04
  • 2021-11-19
  • 2022-12-23
  • 2022-01-26
  • 2021-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2021-11-04
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案