微信小程序post传递参数为formData格式,一般是在上传图片时需要的

  let base64 = 'data:image/png;base64,' + wx.getFileSystemManager().readFileSync(res.tempFiles[0].tempFilePath, 'base64')
    // console.log("base64", base64)
    this.setData({
      base64Code: base64.split(',')[1],
      suffix: res.tempFiles[0].tempFilePath.split('.')[1]
    })
    // console.log(this.data.base64Code, this.data.suffix);
    wx.uploadFile({
      url: 'http://192.168.6.103:8089/crm/app/file/uploadBase64Rotation',
      filePath: res.tempFiles[0].tempFilePath,
      name: 'file',
      formData: {
        base64Code: this.data.base64Code,
        suffix: this.data.suffix
      },
      response: 'json',
      success: (response) => {
        // console.log(response.data);
        const obj = JSON.parse(response.data)
        console.log(obj);
        // console.log(obj.retCode);
        if (obj.retCode == 0) {
          app.$loading()
          this.IDBackUpload(obj)
        } else {
          console.log('上传失败');
        }

      }
    })

wx.uploadFile传参的格式本身就是formData格式的,参照官网就可以

如果是wx.request的需要formData格式,如下图data的格式

IDBackUpload(res) {
    console.log(res);
    wx.request({
      url: 'http://192.168.6.103:8089/app/opportunity/idCardOcrDiscern',
      header: {
        'content-type': 'multipart/form-data; boundary=XXX'
      },
      data: '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="image"' +
        '\r\n' +
        '\r\n' + res.data.fileUrl +
        '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="imageType"' +
        '\r\n' +
        '\r\n' + 2 +
        '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="supplierType"' +
        '\r\n' +
        '\r\n' + 2 +
        '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="papersType"' +
        '\r\n' +
        '\r\n' + 1 +
        '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="idCardSide"' +
        '\r\n' +
        '\r\n' + 'back' +
        '\r\n--XXX' +
        '\r\nContent-Disposition: form-data; name="companyName"' +
        '\r\n' +
        '\r\n' + '资产运营管理-app' +
        '\r\n--XXX',
      method: "POST",
      success: (res) => {
        console.log(res);
        app.$hide()
        if (res.data.data.idCardEffectiveDate == '') {
          wx.showToast({
            title: '识别失败,请再次上传或者联系管理员',
            icon: 'none',
            duration: 2000
          })
        } else if (res.errMsg == 'request:ok') {
          const ocrData = res.data.data
          this.setData({
            'formData.idCardEffectiveDate': ocrData.signIssueDate.substring(0, 10),
            'formData.idCardExpiryDate': ocrData.expiryDate.substring(0, 10),
          })
        }

      }
    })
  },

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

冰冰-ying

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值