axios upload excel file


axios upload excel file

https://github.com/axios/axios/issues/1660

https://stackoverflow.com/questions/52521274/use-axios-to-get-and-save-an-excel-file

https://serversideup.net/uploading-files-vuejs-axios/

https://www.pluralsight.com/guides/asynchronous-file-upload-react

post formData

axios.post( '/single-file', formData, {
    headers: {
        'Content-Type': 'multipart/form-data'
    },
  },
).then(function(){
  console.log('SUCCESS!!');
})
.catch(function(){
  console.log('FAILURE!!');
});

upload component

https://zzk.cnblogs.com/my/s/blogpost-p?Keywords=upload+excel


    postUploadExcel(blob) {
      const {
        name,
        type,
        size,
        lastModified,
        lastModifiedDate,
        webkitRelativePath,
      } = blob;
      // const types = [".xlsx", ".xls", ".csv"];
      const types = ["application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"];
      const littleSize = Math.ceil(size / 1000) <= 500 ? true : false;
      const supportType = types.includes(type) ? true : false;
      const seatMapTemplateId = this.templateId;
      if (supportType) {
        this.isShowWarning = false;
        const formData = new FormData();
        formData.append('file', blob);
        // 😂 不需要 Content-Type, new FormData(), 已經自帶了 `multipart/form-data`
        fetch(`/opapi/v2/seatMap/template/${seatMapTemplateId}/seatData`, {
          method: 'POST',
          // headers: {
          //   'Content-Type': 'application/x-www-form-urlencoded',
          // },
          // mode: 'cors',// no-cors
          // credentials: 'include',
          body: formData,
        })
        .then(res => res.json())
        .then(data => {
          const {
            data: url,
            success,
            errorHint,
            errorCode,
          } = data;
          if(success) {
            this.$message({
              message: '上傳成功',
              type: 'success'
            });
            this.updateURL(url || ``);
          } else {
            this.$message({
              message: `上傳錯誤: ${errorCode}_${errorHint}`,
              type: 'error'
            });
          }
        })
        .catch(error => {
          this.$message({
            message: '上傳錯誤',
            type: 'error'
          });
          console.error(error);
        });
      } else {
        this.isShowWarning = true;
        this.$message({
          type: 'info',
          message: '上傳失敗,請檢查文件大小和類型!'
        });
      }
    },

https://element.eleme.io/#/zh-CN/component/upload

refs



©xgqfrms 2012-2020

www.cnblogs.com 發布文章使用:只允許注冊用戶才可以訪問!



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM