uniapp 中 uni.uploadFile 文件上传踩坑


<button @click='beforeUpload' >上传文件</button>

beforeUpload() {
  const that = this
  const count = 1
  uni.chooseImage({
    count:count,
    success:(res)=> {
      const tempFilePaths = res.tempFilePaths;
      uni.uploadFile({ //循环调用上传单个文件的接口,实现多文件上传
        url: 'http//:xxxxxxx', //仅为示例,非真实的接口地址
        file: res.tempFiles[0],
        name: 'file',
        fileType:'image',
        header:{
          'Authorization': uni.getStorageSync('token') ? "Bearer " +uni.getStorageSync('token') : '',
        },
        success: function (uploadFileRes) {
          
        }
      });
    }
  })
}

 

默认file值以formData格式传输,header中不需要配置Content-Type,若配置Content-Type,传输发生错误


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM