ajax文件上传

softwarePackFileChange() {
      const fileTypes = "exe,rar,zip";
      const fileTypeArray = fileTypes.split(",");

      const softwarePackFile = $("#softwarePackFile").get(0).files[0];
      const filePathArray = softwarePackFile.name.toLowerCase().split(.);
      const fileType = filePathArray[filePathArray.length - 1];
      if (_.indexOf(fileTypeArray, fileType) == -1) {
        $WarnMessage(`支持的附件格式【${fileTypes}】,当前格式:${fileType}。`);
        return;
      }

      const formData = new window.FormData();
      formData.append("file", softwarePackFile);
      formData.append("versionId", this.versionId);
      formData.append("shelfId", this.shelfId);

       $.ajax({
         type: "POST",
         data: formData,
         contentType: false,
         processData: false,
         url: `${$$apiDevOpsPath}/uploadAppPkg`,
         success: response => {
           const message = response.message;
           if (message != undefined) {
             $WarnMessage(message);
           } else {
             const shelfVersionAppPkg = response.model;
             shelfVersionAppPkg.minioHost = response.host;
             this.$emit("pushAppSoftwarePackage", shelfVersionAppPkg);
           }
         },
       });
   
  }

 

ajax文件上传

上一篇:【HTTP学习】HTTP状态集锦


下一篇:Java AtomicInteger