赞
踩
- 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),
- })
- }
-
- }
- })
- },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。