• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
魏无羡的小古板
博客园    首页    新随笔    联系   管理    订阅  订阅

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,传输发生错误

posted @ 2022-02-23 11:21  魏无羡的小古板  阅读(6988)  评论(1)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3