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