我想在单击提交按钮后发布一个csv文件。但是,在单击提交按钮时,其给出的错误表明未将所选文件作为请求添加到发布命令中。请帮忙。以下是我选择文件并将文件提交到服务器的功能的代码片段
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;
}
}