首页
归档
笔记
树洞
搜索
友言

文章详情

Interesting People Record Interesting.

/ uniapp / 文章详情

uniapp上传文件流图片

Sonder
2021-07-31
862字
2分钟
浏览 (5.5k)

需要的结果:

代码如下:

上传文档

复制代码
<button class="idCard-upload__input" @click="handleFileChange"></button>
复制代码
// 触发上传
handleFileChange() {
  let _this = this;
  uni.chooseImage({
    count: 1, //默认9
    sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
    sourceType: ['album'], //从相册选择
    success: (res) => {
      console.log(res,'res')
      uni.uploadFile({
        url: '/v1/user/info/ocr',        //post请求的地址
        filePath: res.tempFilePaths[0], // 传的是BoldURL
        header: {
          token: 'token'
        },
        name: 'imgFile', //后台需要的图片字段
        formData: {
          'type': 'BACK'  //判断是正面还是反面
        },
        success: (uploadFileRes) => {
          //这里要注意,uploadFileRes.data是个String类型,要转对象的话需要JSON.parse一下
          let data = JSON.parse(uploadFileRes.data)
        }
      })
    }
  });
},
下一篇 / Vue.extend创建动态组件的应用

🎯 相关文章

💡 推荐文章

🕵️‍♂️ 评论 (0)