首页 > 解决方案 > 单击提交按钮无法将我的文件发布或提交到服务器

问题描述

单击提交按钮后,我想发布一个 csv 文件。但是,在单击提交按钮时,它会给出错误,指出所选文件未作为请求添加到 post 命令中。请帮忙。以下是我选择文件并将文件提交到服务器的功能的代码片段

fileChangeListener($event) {
    var text = [];
    var files = $event.target.files;

    if (appConstants.validateHeaderAndRecordLengthFlag) {
      if (!this.appService.isCSVFile(files[0])) {
        this.errorMessage = "Please import valid .csv file.";
        this.isFail = true;
        this.fileReset();
        return;
      }
    }

    var input = $event.target;
    let url = "/uploadInspectionReport";
    let token = this.appService.getToken();
    if (token) {
      console.log("file getting", input.files[0])
      this.gettingFile = input.files[0]
      this.buttonStatus = false
    } (err) => {
      console.log("******** Error in uploading inspection records: *********");
      console.log(err);
      this.errorMessage = err;
      this.isFail = true;
    }
}

submitFile(File) {
    //this.confirmationDialogService.confirm('Please confirm..', 'Do you really want to ... ?')
    //.then((confirmed) => console.log('User confirmed:', confirmed))
    //.catch(() => console.log('User dismissed the dialog (e.g., by using ESC, clicking the cross icon, or clicking outside the dialog)'));
    let url = "/uploadInspectionReport";
    let token = this.appService.getToken();
    if (token) {
      this.appService
        .postCsv(url, token, File)
        .subscribe(
          result => {
            console.log("******** Uploaded inspection records *********");
            this.isFileUploaded = true;
            this.csvUploadMessage = result.statusMessage;
          }
        );
    } (err) => {
      console.log("******** Error in uploading inspection records: *********");
      console.log(err);
      this.errorMessage = err;
      this.isFail = true;
    }
}

标签: angulartypescriptpost

解决方案


推荐阅读